Snippets

Iakov Davydov NAS backup script for Unil

Created by Iakov Davydov last modified
#!/bin/bash
## This is a backup script for unil NAS using duplicity.
## By default it will do full backups every three months and incremental every
## time you run it. It will automatically delete backups older than 6 months.
## To use it:
## 1. Change SHARE value to your directory.
## 2. Create ~/.auth and ~/mnt/nasunil directories.
## 3. Create ~/.auth/nas which should look like
##   username=YOURLOGIN
##   password=YOURPASSWORD
##   domain=AD
## 4. Create ~/.auth/npass consisting only of your password.
##   You need to REMEMBER or WRITE IT DOWN. It will be impossible to
##   recover your backup without the password!
## 5. Change DIRS variable so it includes all directories
##   you wish to backup. You probably have to escape spaces if you
##   have them in the directory name. Directories should have different names.
## 6. Make this script executalbe and run (chmod +x nas_bu.sh).
SHARE="//nas.unil.ch/DEE/GROUPS/gr-Salamin/PRIVE/yourlogin"
CRED="$HOME/.auth/nas"
PASS="$HOME/.auth/npass"
MOUNT_PATH="$HOME/mnt/nasunil"
BACKUP_PATH="$MOUNT_PATH/bu"
DUPL_OPTS="--exclude-if-present .duplignore --progress \
	--full-if-older-than 3M"
DIRS="$HOME/work $HOME/docs $HOME/Documents"

sudo mount -t cifs -o credentials="$CRED",uid=1000,gid=1000,rw \
    "$SHARE" "$MOUNT_PATH" || { echo "error mounting"; exit 32; }
export PASSPHRASE="$(cat "$PASS")"
mkdir -p "$BACKUP_PATH"
for source in $DIRS
do
	echo "Source: $source"
	target="file://$BACKUP_PATH/$(basename "$source")"
	duplicity $DUPL_OPTS "$source" "$target"  && \
	duplicity remove-older-than 6M --force "$target"
done
unset PASSPHRASE

sudo umount $MOUNT_PATH

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.