backup

A simple system backup utility
git clone git://git.danielmoch.com/backup.git
Log | Files | Refs

commit 9fbb546d5ed554fa671fd2b553a35686d4461de7
parent 8eedfbb0e9133b2bfb266013244540a97f78bd73
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 19 Jun 2018 06:06:41 -0400

Early revisions to generalize script

Diffstat:
MTODO.txt | 6+-----
Mbackup | 76+++++++++++++++++++++++++++++++++++++++-------------------------------------
Aconfig | 6++++++
3 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -1,5 +1 @@ -1. Config file to parameterize - a. Auto mount - b. Folders to back up - c. Destination folder -2. backup --init should run Borg init (and generate a password?) +1. backup --init should run Borg init (and generate a password?) diff --git a/backup b/backup @@ -1,62 +1,64 @@ #!/bin/sh -OUTPUT=/var/log/tc_backup.log +[ -n "$BACKUP_OUTPUT" ] && exec 1> $BACKUP_OUTPUT 2>&1 if [ $EUID -ne 0 ] then - echo "`date`: Must be run as root" >> $OUTPUT + echo "`date`: Must be run as root" exit 1 fi -TC_MOUNTPOINT=/mnt/timecapsule -TC_SERVER=timecapsule.djmoch.org -PASSFILE=/root/secret/ft __cleanup() { - if [ -n "$TC_MOUNTED" ] + if [ -n "$BACKUP_MOUNTED" ] then - umount $TC_MOUNTPOINT - echo "Time Capsule unmounted" >> $OUTPUT - unset TC_MOUNTED + umount $BACKUP_MOUNTPOINT + echo "Time Capsule unmounted" + unset BACKUP_MOUNTED fi } -echo "Beginning backup: `date`" >> $OUTPUT +echo "Beginning backup: `date`" -# Only do the following if server is reachable -starttime=`date '+%s'` -runningtime=0 -while [ $runningtime -le 120 ] -do - if ping -c 1 danielmoch.com > /dev/null 2>&1 +# Only do the following if backing up to a server +if [ -n "$BACKUP_SERVER" ] +then + starttime=`date '+%s'` + runningtime=0 + while [ $runningtime -le 120 ] + do + if ping -c 1 $BACKUP_SERVER > /dev/null 2>&1 + then + connected=1 + break + fi + sleep 1 + runningtime=$((`date '+%s'` - $starttime)) + done + + if [ -n "$connected" ] then - connected=1 - break + echo "$BACKUP_SERVER reachable. Proceeding." + else + echo "$BACKUP_SERVER NOT reachable. Exiting." + echo "Ending backup: `date`" + exit -1 fi - sleep 1 - runningtime=$((`date '+%s'` - $starttime)) -done - -if [ -n "$connected" ] -then - echo "$TC_SERVER reachable. Proceeding." >> $OUTPUT -else - echo "$TC_SERVER NOT reachable. Exiting." >> $OUTPUT - echo "Ending backup: `date`" >> $OUTPUT - exit -1 fi -if mount $TC_MOUNTPOINT >> $OUTPUT 2>&1 +if mount $BACKUP_MOUNTPOINT 2>&1 then - echo "Time Capsule successfully mounted" >> $OUTPUT - TC_MOUNTED=1 + echo "Time Capsule successfully mounted" + BACKUP_MOUNTED=1 else - echo "Time Capsule mount FAILED. Quitting." >> $OUTPUT - echo "Ending backup: `date`" >> $OUTPUT + echo "Time Capsule mount FAILED. Quitting." + echo "Ending backup: `date`" exit -2 fi -BORG_PASSPHRASE=`cat $PASSFILE` borg create --stats /mnt/timecapsule/$HOSTNAME.borg::`date '+%Y%m%d'` /etc /root /home >> $OUTPUT 2>&1 +BORG_PASSPHRASE=`cat $PASSFILE` borg create --stats \ + $BACKUP_MOUNTPOINT/$HOSTNAME.borg::`date '+%Y%m%d'` \ + $BACKUP_FOLDERS 2>&1 -df | grep "Filesystem\|$TC_MOUNTPOINT" >> $OUTPUT +df | grep "Filesystem\|$BACKUP_MOUNTPOINT" __cleanup -echo "Ending backup: `date`" >> $OUTPUT +echo "Ending backup: `date`" diff --git a/config b/config @@ -0,0 +1,6 @@ +#BACKUP_OUTPUT= +#BACKUP_MOUNTPOINT= +#BACKUP_SERVER= +#BACKUP_PASSFILE= +#BACKUP_DEST= +#BACKUP_FOLDERS=