snackup (was: Re: [gentoo-user] backup to a cold-swap drive)
Iain Buchanan writes: On Thu, 2010-04-29 at 16:44 +0200, Alex Schuster wrote: using this script, adapted to their needs, I started to rewrite it in a way that it reads a config file, and no modification of the script itself is necessary. If anyone is interested, send me an email. interested! So is it on sourceforge yet ;) Sorry, it took a little longer. I was ill, and then these scripts tend to grow and grow until I am satisfied with them. It's still not perfect, but I think at the moment it does what it should do. Still not on sourceforge, but here: http://www.wonkology.org/utils/snackup The name is silly, but I kinda like it now. A backup utilizing LVM snapshots... snapshot backup... snackup! It needs a config file that is looked up in some default locations, or can be specified with the -c option. Use option -T to generate a template that has information on the syntax and some examples. In short: The config file defines targets you give as arguments to snackup. So 'snackup home' backs up your /home partition, 'snackup etc' creates a .tgz file of your /etc. The config file is sourced, so you can put any bash stuff you want into there, like some shell functions you want to have executed. For example, I want my /var/log/portage/*.log files to be compressed before I backup my /var partition. A target is started by a colon, followed by name, type, source and destination (and optionally more), separated by one or more tab characters. Type can be 'cp', 'dd', 'tar', 'rsync' or 'rdiff'. I only tested dd, tar and rdiff so far, though. The source directory may be prefixed by the volume group and LVM of that partition in order to create an lvm snapshot first. You may add a LUKS key if the partition is encrypted. The source may contain wildcards. In that case, all matching files are backed up to the destination. If the type has a * appended, all matching files are backed up individually. Some examples: : tar kde .kde* /backup/kde.%s Target 'kde' will backup all your .kde* directories to /backup/kde.tar (the %s is replaced by a suffix, usually tar). You need to be in your home directory, otherwise the path will not be found. This is not necessary if you use ~//.kde* instead. : kernels tar*/usr/src//linux-* /backup/src/%f.%s -j - lsf Target 'kernels' will backup your /usr/src/linux-* directories individually - one tar file for each (note the * appendended to the tar target type). The -z option will be passed to the tar command, and the suffix is changed to tgz accordingly. The // denotes that the backup should be done locally from the directory left to the //. Otherwise, the full path would be included in the tar file. : tar etc /etc/backup/etc_%d.%s -j Target 'etc' will tar your /etc directory, compressed with bzip2. The %d will be replaced by the current date. You can change the date format by re-defining a date() shell function. You will get a message about tar removing the leading /, you can avoid it by replacing /etc by ///etc, meaning that your local directroy will be /. : bootdd /dev/sda5 /dev/sdb5 bs=32M Target 'boot' will backup a boot partition with dd. Options like the bs=32M are added directly to the dd command. : homersync system/home::. /backup/home/ Target 'home' will create a LVM snapshot of the /dev/system/home logical volume, mount it and back it up with rdiff-backup. The '.' could also be a / or left off. : var rsync system/var::/ /backup/var/- ziplog Similar, but the command ziplog will be executed before the backup, compressing some log files. It must be defined in the config file. The script has some options: -c file location of config file -C clear destination first -d dummy mode, just show what would be done -f force backup (the initial rdiff-backup may need this) -h show this help -l output to log file, too -L log file (default:/home/wonko/log/snackup.log); may be a directory (add a trailing slash) to create target-specific logs -n luse nice level l (default:10, 0 to turn off) -N luse ionice level l (default:3, 0 to turn off) -o extra options that will added to the actual backup command -s size size of LVM snapshot (default:2G) -S char replace tab as delimiter for targets in config file -T output config file template -v verbose output; may be given multiple times 1: some extra output; 2: add -v to commands; 3: set -xv -V output version information and exit Most important are: -c to specify the location of the config file -d to output what would be done, you will see the final tar / rdiff- backup / whatever command with all its options. -T to see a template. Save it with snackup
Re: snackup (was: Re: [gentoo-user] backup to a cold-swap drive)
Alex Schuster wo...@wonkology.org wrote: Iain Buchanan writes: On Thu, 2010-04-29 at 16:44 +0200, Alex Schuster wrote: using this script, adapted to their needs, I started to rewrite it in a way that it reads a config file, and no modification of the script itself is necessary. If anyone is interested, send me an email. interested! So is it on sourceforge yet ;) Sorry, it took a little longer. I was ill, and then these scripts tend to grow and grow until I am satisfied with them. It's still not perfect, but I think at the moment it does what it should do. Still not on sourceforge, but here: http://www.wonkology.org/utils/snackup The name is silly, but I kinda like it now. A backup utilizing LVM snapshots... snapshot backup... snackup! It needs a config file that is looked up in some default locations, or can be specified with the -c option. Use option -T to generate a template that has information on the syntax and some examples. In short: The config file defines targets you give as arguments to snackup. So 'snackup home' backs up your /home partition, 'snackup etc' creates a .tgz file of your /etc. The config file is sourced, so you can put any bash stuff you want into there, like some shell functions you want to have executed. For example, I want my /var/log/portage/*.log files to be compressed before I backup my /var partition. A target is started by a colon, followed by name, type, source and destination (and optionally more), separated by one or more tab characters. Type can be 'cp', 'dd', 'tar', 'rsync' or 'rdiff'. I only tested dd, tar and rdiff so far, though. The source directory may be prefixed by the volume group and LVM of that partition in order to create an lvm snapshot first. You may add a LUKS key if the partition is encrypted. The source may contain wildcards. In that case, all matching files are backed up to the destination. If the type has a * appended, all matching files are backed up individually. Some examples: : tar kde .kde* /backup/kde.%s Target 'kde' will backup all your .kde* directories to /backup/kde.tar (the %s is replaced by a suffix, usually tar). You need to be in your home directory, otherwise the path will not be found. This is not necessary if you use ~//.kde* instead. : kernels tar*/usr/src//linux-* /backup/src/%f.%s -j - lsf Target 'kernels' will backup your /usr/src/linux-* directories individually - one tar file for each (note the * appendended to the tar target type). The -z option will be passed to the tar command, and the suffix is changed to tgz accordingly. The // denotes that the backup should be done locally from the directory left to the //. Otherwise, the full path would be included in the tar file. : tar etc /etc/backup/etc_%d.%s -j Target 'etc' will tar your /etc directory, compressed with bzip2. The %d will be replaced by the current date. You can change the date format by re-defining a date() shell function. You will get a message about tar removing the leading /, you can avoid it by replacing /etc by ///etc, meaning that your local directroy will be /. : bootdd /dev/sda5 /dev/sdb5 bs=32M Target 'boot' will backup a boot partition with dd. Options like the bs=32M are added directly to the dd command. : homersync system/home::. /backup/home/ Target 'home' will create a LVM snapshot of the /dev/system/home logical volume, mount it and back it up with rdiff-backup. The '.' could also be a / or left off. : var rsync system/var::/ /backup/var/- ziplog Similar, but the command ziplog will be executed before the backup, compressing some log files. It must be defined in the config file. The script has some options: -c file location of config file -C clear destination first -d dummy mode, just show what would be done -f force backup (the initial rdiff-backup may need this) -h show this help -l output to log file, too -L log file (default:/home/wonko/log/snackup.log); may be a directory (add a trailing slash) to create target-specific logs -n luse nice level l (default:10, 0 to turn off) -N luse ionice level l (default:3, 0 to turn off) -o extra options that will added to the actual backup command -s size size of LVM snapshot (default:2G) -S char replace tab as delimiter for targets in config file -T output config file template -v verbose output; may be given multiple times 1: some extra output; 2: add -v to commands; 3: set -xv -V output version information and exit Most important are: -c to specify the location of the config file -d to output what would be