I’m making backups with rsnapshot. The path to the backups looks like this:
name=$(date +"%Y-%m-%d_%H-%M")
/backup/hourly.0/"$name"
In a perl script I choose from the the different snapshots to make diffs to the files in my home directory.
my $backup = '/backup';
opendir my $dh, $backup or die $!;
my @versions;
while ( defined( my $version = readdir $dh ) ) {
# ...
push @versions, $version;
}
# choose from @versions
# do something with the choosen
Is there a way to lock the backup directory, so that rsnapshot doesn’t begin to rotate the snapshots while I am running my script?
You cannot lock a directory with an exclusive lock because exclusive locks require that the file be opened for reading and writing, and directories cannot be opened for reading & writing. You could lock a file instead, but remember that file locks are advisory. So if
rsnapshotdoes not also lock the directory then you are locking it and nobody else is paying attention to your lock and it doesn’t accomplish anything.Some options:
rsnapshotlock it..0,.1, etc… so that you don’t need to rotate them.