mackup
A utility for performing arbitrary backup processes in a standard manner.
Quickstart
Install mackup
via apt-get
.
# echo 'deb http://pkg.bueller.ca/debian stable main' > /etc/apt/sources.list.d/pkg.bueller.ca.list
# apt-get update
# apt-get install mackup
Or install mackup
manually.
# wget http://www.bueller.ca/downloads/software/mackup/mackup_0.3.1-1_all.deb
# dpkg -i mackup_0.3.1-1_all.deb
Create a directory to store the backup.
# mkdir /var/backups/mackup
Determine which days to perform backups.
# cd /var/backups/mackup
# mkdir mon tues wed thu fri
Configure sources to backup.
# echo '/etc' >> /etc/mackup/sources
# echo '/home' >> /etc/mackup/sources
# echo '/root' >> /etc/mackup/sources
Configure a backup utility. In this case it will be rsync.
# echo <<EOF > /etc/mackup/run
#!/bin/sh
rsync -av --delete $1/$2 $3/
EOF
# chmod +x /etc/mackup/run
Add mackup
to cron. Use macklog
to capture and timestamp output from mackup
and provide log rotation.
# echo <<EOF > /etc/cron.daily/mackup
#!/bin/sh
mackup /var/backups/mackup | macklog /var/log/mackup 10000000 10
EOF
# mkdir /var/log/mackup
That's it. When mackup
runs, it will check /var/backups/mackup
to see if a backup is scheduled. If it's Monday, mackup will look for a directory called mon
, or if it's Tuesday, a directory called tue
, etc. If a backup is schedule, then /etc/mackup/run
is executed and rsync will be used to copy the directories specified in /etc/mackup/sources
into /var/backups/mackup/mon/data
. Output is logged and managed by macklog
and written to /var/log/mackup/current
. When /var/log/mackup/current
exceeds 10MB, it will be rotated. macklog
will only keep a maximum of 10 log files in /var/log/mackup
.
Synopsis
mackup dir
macklog dir [ size [ count ] ]
Description
mackup
allows an administrator to backup parts of a system (or systems) in a standard manner using multiple secondary utilities (such as tar
or rsync
) simply by managing plaintext files. Modifying the contents of these files adjusts the behaviour of the backup, reducing redundancy in scripting the backups by hand while allowing other programs to easily edit and maintain the contents of the files. Abstracting the schedule of the backups from the backup utilities themselves also allows the administrator to change the backup utility, and automatically have the same backup schedule continue.
If the current day is Monday, and the dir/mon
directory exists, then all the sources listed in dir/on/sources
will be backed up individually into dir/mon/data
. If dir/mon/sources
doesn't exist, mackup
will look for sources in /etc/mackup/sources
. If this file doesn't exist, the search stops and an error is produced. For example, if dir/mon/sources
contained /etc/
, then on Monday the /etc/
folder would be tar
d and stored in dir/mon/data/etc.tar
. dir/mon/data
is created automatically if it doesn't exist.
Similariliy, if it's the 3rd of the month and dir/3
exists, then all sources listed in dir/3
will be tar
d. If both dir/mon
and dir/3
exist, both directories will be processed.
Lastly, if the directory dir/daily
exists, it will processed every day.
While the sources
file lists the location that need to be backed up, the run
file specifies the command that actually performs the backup. This file is actually a script that is called by mackup
and is passed the following arguments: tdir
, t
, bdir
, b
. tdir
is the target parent directory for the backup, t
is the actual backup target which lives in tdir
, bdir
is the backup target directory and b
is the backup target.
mackup
will produce output during it's run. The contents of this output is a mix of notice and error messages as well as the current file path being backed up. This output can be capture and sent to a log file with either the included logging utility macklog
or with a third-party utility such as multilog
by Dan Bernstein.
macklog
reads input on stdin
and writes it to the file dir/current
. Each line is prepended with a timestamp using the date
format %Y%m%d%H%M%S (or [year][month][day][hour][minute][second]). macklog
will also perform log rotation if supplied with the size
parameter. Once dir/current
equals or exceeds size
, it is renamed to the timestamp of the last line written to it. If count
is specified, then only count
number of the latest rotated log files will be kept. Anything older will be deleted.
Options
mackup
dir
The directory thatmackup
should look in for configuration data.
macklog
dir
The directory thatmacklog
should log to.size
The size the current file should reach before rotating it. If not specified, no rotation will occur.count
The number of log files to keep after rotation. Older log files will be deleted first.
Files
sources
The list of locations to backup.run
The script that is executed to process the backup.
Comments