Skip to content

Instantly share code, notes, and snippets.

@quijot
Created April 28, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quijot/308af88546bb222dd430c278db88f733 to your computer and use it in GitHub Desktop.
Save quijot/308af88546bb222dd430c278db88f733 to your computer and use it in GitHub Desktop.
Automatic backup with duplicity for Zentyal (>= 4)
#!/usr/bin/env bash
#################################################
# remember to add execution rights to this script
#################################################
# Usage:
# $ backup full
# $ backup incr|incremental
# $ backup check
# $ backup remove-old
BACKUP_DIR=/home/backups/estudio-data
VOLUME_SIZE=600
KEEP_LAST=2
if [ "$1" = "full" ] || [ "$1" = "incr" ] || [ "$1" = "incremental" ]; then
# Full|Incremental copy:
duplicity $1 --volsize $VOLUME_SIZE \
--exclude=/home/samba/shares/*/RecycleBin \
--exclude=/srv/ftp/*/RecycleBin \
--exclude=/srv/ftp/varios/downloads \
--include=/var/tmp \
--include=/home/santi/devel \
--include=/home/samba/shares \
--include=/srv/ftp \
--include=/var \
--exclude='**' \
/ file://$BACKUP_DIR --no-encryption
elif [ "$1" = "check" ]; then
# Checking the collection status:
duplicity collection-status file://$BACKUP_DIR --no-encryption
elif [ "$1" = "remove-old" ]; then
# Remove old backups, keeping last $KEEP_LAST:
duplicity remove-all-but-n-full $KEEP_LAST --force \
file://$BACKUP_DIR --no-encryption
else
echo "Did Nothing!"
fi
# copy this file to /etc/cron.d/
# "test $(date +\%w) -eq 5" means Friday
# so this makes full backup every Friday 22:00hs
# and incremental backup every other day 22:00hs
0 22 * * * root test $(date +\%w) -eq 5 && nice -n 10 /home/santi/devel/backup full && nice -n 10 /home/santi/devel/backup remove-old
0 22 * * * root test $(date +\%w) -ne 5 && nice -n 10 /home/santi/devel/backup incremental
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment