0

From https://rsync.samba.org/examples.html, there are two backups in the following example, where the first backup is done by find and cp, and the second by rsync. My question is about the first backup.

I use rsync to backup my wifes home directory across a modem link each night. The cron job looks like this

#!/bin/sh
cd ~susan
{
echo
date
dest=~/backup/`date +%A`
mkdir $dest.new
find . -xdev -type f \( -mtime 0 -or -mtime 1 \) -exec cp -aPv "{}"
$dest.new \;
cnt=`find $dest.new -type f | wc -l`
if [ $cnt -gt 0 ]; then
  rm -rf $dest
  mv $dest.new $dest
fi
rm -rf $dest.new
rsync -Cavze ssh . samba:backup
} >> ~/backup/backup.log 2>&1

note that most of this script isn't anything to do with rsync, it just creates a daily backup of Susans work in a ~susan/backup/ directory so she can retrieve any version from the last week.

The last line does the rsync of her directory across the modem link to the host samba. Note that I am using the -C option which allows me to add entries to .cvsignore for stuff that doesn't need to be backed up.

My questions are

  1. Is "in a ~susan/backup/ directory" specified by 'dest=~/backup/date +%A'? Does ~ in dest mean the home directory of the user who runs the script, who might not be Susan so ~ might not mean ~susan?

  2. Is "a daily backup" specified by \( -mtime 0 -or -mtime 1 \)? Does \( -mtime 0 -or -mtime 1 \) mean files modified within the past 48 hours, instead of the past 24 hours?

Thanks.

1

Is "in a ~susan/backup/ directory" specified by 'dest=~/backup/date +%A'?

Yes, so you're right, the implementation doesn't quite match the spec.

Does ~ in dest mean the home directory of the user who runs the script, who might not be Susan so ~ might not mean ~susan?

Yes. But the script needs to run as susan or root anyway to be sure to access all of Susan's files. It's presumably intended to be run by Susan (or cron acting for her).

Is "a daily backup" specified by ( -mtime 0 -or -mtime 1 )?

I would consider "daily" to be determined by what ever is running the script, presumably cron (or nowadays, a systemd timer).

Does ( -mtime 0 -or -mtime 1 ) mean files modified within the past 48 hours, instead of the past 24 hours?

Yes. -mtime 0 means "whose modification timestamp compared to now, rounded down to the nearest 24h, is 0 × 24h", and likewise for -mtime 1, so this finds everything modified in the last 48h (well, strictly less than 48h). You need this to catch a full 24 hours' worth of changes, taking into account start time variations with daily jobs.

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.