Write backup script that only selects one file
Q I use Simple Linux Backup, which produces daily backups in the following form: Backup.Mon.tar.gz Backup.Tue.tar.gz Backup.Wed.tar.gz ... Of these, the Monday backup is the full one, the others are incremental. I run two versions of Simple Linux Backup; one is run as root and backs up certain system files, the other is run as my user and backs up my data. They both produce the same file names - but one set is stored in /mnt/backup/ system/ and the other set is stored in /mnt/backup/data/. I am now trying to write a script to copy these files onto DVD. Of the files it is only the respective Backup.Mon.tar.gz (full backup) files that I want to keep - I intend to run this as a cron job each Monday after the backups have completed. The problem is that I can't just use
growisofs -Z /dev/dvd R -J /mnt/backup/*
as I get a load of files I don't want (and it wouldn't fit on one DVD). Nor can I use
growisofs -Z /dev/dvd -R -J /mnt/backup/system/Backup.Mon.tar.gz /mnt/backup/data/Backup.Mon.tar.gz
because the file names are the same! I suppose I could rename one of the files in my script before writing the DVD, but that just seems like an ugly solution. As far as I can tell growisofs does not support the -o switch to write the files as different file names. Can you offer a more elegant solution?
A There are a number of ways you could do this, all of which use mkisofs arguments. growisofs passes most of it arguments to mkisofs to create the ISO data, only those arguments related to writing the data to the disc belong to growisofs. The one mkisofs argument that is not allowed is the one you mention, -o, because this causes mkisofs to write the ISO data to a file and the whole point of growisofs is to write data to a disc. One option is to use the -m option to exclude everything but the Monday files. This will exclude every backup where the day part of the name does not start with M.
growisofs -Z /dev/dvd -R -J -m 'Backup.[^M]??.tar.gz' /mnt/backup
A more flexible method is to use the graft-points argument. This can take a little getting used to, but it allows you to change the name or path of any file or directory you write to the disc.
growisofs -Z /dev/dvd -R -J -graft-points system.tar.gz=/mnt/backup/system/Backup.Mon.tar.gz data.tar.gz=/mnt/backup/data/Backup.Mon.tar.gz
will save the two files as system.tar.gz and data.tar.gz in the root of the DVD. An improved version of the command includes the date of the Monday backups in both the volume name of the DVD and each of the files, making it easier to see at a glance which DVD is current.
DATE=$(date --reference /mnt/backup/system/Backup.Mon.tar.gz +%y%m%d) growisofs -Z /dev/dvd -R -J -graft-points -V BACKUP_$DATE system_$DATE.tar.gz=/mnt/backup/system/Backup.Mon.tar.gz data_$DATE.tar.gz=/mnt/backup/data/Backup.Mon.tar.gz
The mkisofs man page has (a lot) more details. Remember also that if your distro uses cdrkit rather than cdrtools (cdrkit's licencing is more acceptable to some distros, particularly those based on Debian) mkisofs is replaced by genisoimage, although there is a symlink for mkisofs to retain compatibility.
- Backup script not working in cron
- Recover file backup operations after network disconnection
- Imaging backup solution
- Problems with Bash script to install packages
- Choosing backup software