Home > linux, system administration > Backup using rdiff-backup: a bash select menu

Backup using rdiff-backup: a bash select menu

This is a bash backup script, that uses rdiff-backup to perform “semi-automatic” backups. (I need to press two keys, to start a backup)

So, what does it do?

First there are some global options (mainly for debugging)
The exclude and include variables are links to the include/exclude files. (in this file you specify which folders to backup)
The “backup” variable: this is where rdiff-backup gets started.

Then a select menu is drawn (as described in a previous post.
The first option checks if my external HDD is mounted, if it is, it does the backup.
The second options checks if I am at home (based on IP), if I am it does the backup to a local file server.
The third option does the same, but on my work network. (it uses public IPs, so it is removed)
The fourth option (“l”), lists the different versions on my local backup.
The “p” option pulls some other backups that are automatically generated on a server to my laptop.

#!/bin/bash
##
options="-v 5 --print-statistics "
exclude="--exclude-globbing-filelist $HOME/.scripts/tools/backup-lists/exclude"
include="--include-globbing-filelist $HOME/.scripts/tools/backup-lists/include"
backup="rdiff-backup $options $exclude/$target $include/$target --exclude '**' / $backuppath"
while :
do
#clear
echo "****************************************"
echo "* Backup using rdiff-backup *"
echo "****************************************"
echo "* [1] Backup to external hdd *"
echo "* [2] Backup to server @home *"
echo "* [3] Backup to work-server *"
echo "* [l] List increments ext hdd *"
echo "* [p] Pull backups work-server *"
echo "* [0] Exit/Stop *"
echo "****************************************"
echo -n "Enter your menu choice [1-5]: "
read yourch
case $yourch in
1) target="ext-hdd"
mount | grep /media/disk-1 > /dev/null
if [ $? -eq 0 ]
then
echo loop1
backuppath="/media/disk-1/autobackuplaptop/"
backup
echo "Backup to external hdd finished, Press Enter to continue. . ."
else
echo "Error no external harddisk connected!"
echo "Press Enter to continue. . ."
fi
read
exit 0;;
2) backuppath="server.local::/zfs-raidz/backup/autobackuplaptop/"
target="ubuntuserver"
ifconfig | grep 192.168.123 > /dev/null
if [ $? -eq 0 ]
then
backup
echo "Backup to ubuntuserver finished, Press Enter to continue. . ."
else
echo "You are not at home, ubuntuserver not reachable"
echo "Backup to ubuntuserver failed, Press Enter to continue. . ."
fi
read
exit 0;;
3) backuppath="work...."
l) rdiff-backup -l --list-increment-sizes /media/disk-1/autobackuplaptop
echo "Press Enter to continue. . ."
read
exit 0;;
p) scp -rp -P 55555 me@11.11.11.11:/home/backup/tar $HOME/data/backup
echo "Press Enter to continue. . ."
read
exit 0;;
0) exit 0;;
*) echo "Oopps!!! Please select 1,2,3,4, or 5";
echo "Press Enter to continue. . ." ; read ;;

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: