As an update, I've been using my "pre" command for the last week or so with no problems. It's quite handy, I find, to be able to create such detailed backups with a quick command before I edit a file.
I've updated the "pre" script to accept the input of files from the current working directory (without full paths).
Code:
#!/bin/bash
# /usr/local/bin/pre
# Author: Russell Pinkston
# March 10, 2013
# License: GPL
#
# pre [file]
#
# Creates a link to, and a dated backup of, [file] in ~/.config/backups/
FILE=$1
for f in "$( readlink -f "$( dirname "$FILE" )" )/$( basename "$FILE" )" ;
do
cp -bu "$f" ~/.config/backups/"`basename ${f}`".$(date +%F) ;
ln -sf "$f" ~/.config/backups/"`basename ${f}`.ln" ;
done
I've also come to the realization that, though this script is handy for backing up a file before I edit it, it does not keep a backup of the linked file's current state. For example, if I were to run a deja-dup backup of my /home directory, the files in my ~/.config/backups/ folder would only be backups of the previous states (from running "pre"), and not their current states. This is what papibe's script would be useful for. So, I've taken what papibe gave me and edited it to work with the same parameters as "pre." I've named it "post" and have also put it in my /usr/local/bin folder.
Code:
#!/bin/bash
# /usr/local/bin/post
# Author: Russell Pinkston
# March 10, 2013
# License: GPL
#
# Creates a copy of the current state of all links at ~/.config/backups/*.ln
# Renames each copy as basename.YYYY.MM.DD
for f in ~/.config/backups/*.ln;
do
cp -bu "$f" "${f%.*}".$(date +%F) ;
done
So, now I can run "$ pre [file]" on the command line to back up a file before editing it. And I can run "$ post" at any other time to create backups of all the linked files after editing them.
Pretty snazzy. If anyone has any suggestions for the code of these scripts, let me know. I would also like to be able to add something to the "post" script where it will only create a new backup if the file has changed since the latest backup.
Bookmarks