2

I have a script that automates backups - hourly snapshots of my xubuntu 12.04LTS workstation. It creates a directory named according to the date and time, ie: 20140316-1033, representing 10:33 this morning, March 16th. The backup works flawlessly, hard links functioning as they should.

That changed two days ago. I had been running it manually - sporadically, and finally I decided to have cron automate the task, running it once an hour. I changed the verbosity within the script, a couple tweaks as to what was being copied with each backup. So, I apparently changed something, and I cannot figure out what I did.

When I check the creation date of the target directory, it is always March 14th, 2014 at 11:23. Up until I started fiddling, it worked properly. Since then, the creation dates are static.

Because of this, I have had to change the script so that it uses directory names rather than creation dates of the directories to determine the most recent snapshot for the snapshot.

Anything you can point me to would be greatly appreciated. Thanks in advance.

SOURCE="/"
NOW=$(date +"%Y%m%d-%H%M")
BASE="/media/backup-internal/furgesson"
PREVIOUS=$(ls -r $BASE | head -1)

if [[ "$NOW" != "$PREVIOUS" ]];
then
    TARGET="$BASE/$NOW"
    LINK="$BASE/$PREVIOUS"
    OPTIONS="-avH --delete --link-dest=$LINK"
    rsync $OPTIONS --include-from '/home/carolyn/BackupScripts/include-list.txt' --exclude-from '/home/carolyn/BackupScripts/exclude-list.txt' $SOURCE $TARGET
fi

And here is what the directory listing looks like...

total 124
drwxr-xr-x 25 root root 4096 Mar  7 04:04 20140314-0445
drwxr-xr-x 25 root root 4096 Mar 14 04:48 20140314-0512
drwxr-xr-x 25 root root 4096 Mar 14 04:48 20140314-0515
drwxr-xr-x 25 root root 4096 Mar 14 04:48 20140314-0821
drwxr-xr-x 25 root root 4096 Mar 14 04:48 20140314-0822
drwxr-xr-x 23 root root 4096 Mar 14 09:38 20140314-1013
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-1140
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-1314
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-2059
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-2128
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-2141
drwxr-xr-x 23 root root 4096 Mar 14 11:23 20140314-2144
drwxr-xr-x  3 root root 4096 Mar 14 11:23 20140315-0846
drwxr-xr-x  3 root root 4096 Mar 14 11:23 20140315-0848
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-0849
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-0856
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1125
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1135
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1138
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1405
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1409
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1433
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1533
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1633
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1733
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1833
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140315-1933
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140316-0733
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140316-0833
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140316-0933
drwxr-xr-x  4 root root 4096 Mar 14 11:23 20140316-1033
0

A few small issues:

  1. You should never parse ls. That said, in this case, you seem to have full control of the file names in your target directory so ls can be an option. However, I recommend you use ls -tr so sort by time, instead of alphabetically:

    PREVIOUS=$(ls -tr $BASE | head -n 1)
    
  2. Let's have a look at your rsync options. -a equals -rlptgoD:

    -r, --recursive             recurse into directories
    -l, --links                 copy symlinks as symlinks
    -o, --owner                 preserve owner (super-user only)
    -g, --group                 preserve group
    -t, --times                 preserve modification times
    

    The problem is the -t, this preserves the real modification time of the source files so it does not actually set the modification date of the backup to the time the backup was created bu to the last modification time of the original files. Replace -a with -rlog (removing -t) to set the time to what you are expecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.