Skip to content

Instantly share code, notes, and snippets.

@holderbaum
Created November 21, 2010 10:59
Show Gist options
  • Save holderbaum/708645 to your computer and use it in GitHub Desktop.
Save holderbaum/708645 to your computer and use it in GitHub Desktop.
read the comment ^^
#!/bin/bash
# A generator for a nicely tweaked rsnapshot configuration
# it collects in and exclude from rsnapshot files in the VZ and the Host roots.
# such files could look like following:
# > cat /rsnapshot
# /
# !/var/log
# !/tmp
# this would include everything, except /var/log and /tmp.. What a GREAT and SIMPLE
# syntax.. No more fiddling in rsnapshot.conf
# remember, this is a first test, not a final and bugfree version.. (:
# after running this run "rsnapshot -c /etc/rsnapshot.tmp.conf BlaaaFooo"
TMP_CONF="/etc/rsnapshot.tmp.conf"
BACKUP_ROOT="/backup"
RSNAPSHOT_CONF="/rsnapshot"
RSNAPSHOT_VZ_CONF="/rsnapshot"
VZ_ROOT="/var/lib/vz/private"
TMP_VZ_ROOT="/container"
HOSTNAME=$(hostname -f)
cat > $TMP_CONF << -EOF
config_version 1.2
snapshot_root $BACKUP_ROOT/
cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_logger /usr/bin/logger
cmd_du /usr/bin/du
#cmd_preexec /path/to/preexec/script
#cmd_postexec /path/to/postexec/script
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 1
verbose 3
loglevel 3
logfile /var/log/rsnapshot.log
lockfile /var/lock/rsnapshot.pid
-EOF
if [ ! -L $TMP_VZ_ROOT ]; then
sudo ln -s $VZ_ROOT $TMP_VZ_ROOT
fi
for i in $(cat $RSNAPSHOT_CONF|egrep "^!.*"|sed "s/^!\(.*\)/\1/"; echo $VZ_ROOT;echo $TMP_VZ_ROOT)
do
printf "exclude\t$i\n" >> $TMP_CONF
done
for i in $(cat $RSNAPSHOT_CONF|egrep -v "^!.*"; echo $RSNAPSHOT_CONF)
do
printf "backup\t$i\t$HOSTNAME/system/\n" >> $TMP_CONF
done
for vz in $(ls $TMP_VZ_ROOT)
do
conf=$TMP_VZ_ROOT/$vz$RSNAPSHOT_VZ_CONF
if [ -f $conf ]; then
echo "# backup-directives for vz: $vz" >> $TMP_CONF
for include in $(cat $conf|egrep -v "^!"; echo "$RSNAPSHOT_VZ_CONF")
do
include=$TMP_VZ_ROOT/$vz$include
printf "backup\t$include\t$HOSTNAME/\n" >> $TMP_CONF
done
for exclude in $(cat $conf|egrep "^!"| sed 's/^!\(.*\)/\1/i')
do
exclude="$TMP_VZ_ROOT/$vz$exclude"
printf "exclude\t$exclude\n" >> $TMP_CONF
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment