backup

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

commit 985943ea55bad0b0782c6ad86ac6512fc8f98291
parent ca908d2ecdf55807620ed7c04999a2c475e76da5
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 19 Feb 2019 04:58:30 -0500

Final revisions. Ready for test.

Diffstat:
Mbackup | 24+++++++++++++-----------
Mbackup.service | 2+-
Mconfig | 26+++++++++++++++++++++++++-
3 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/backup b/backup @@ -1,13 +1,15 @@ #!/bin/sh +# vim: set sts=4 sw=4 et: BACKUP_CONFIG=/etc/backup/config -BACKUP_PASSFILE=/etc/backup/passwd -BACKUP_DEST=/var/backup +BACKUP_PASSWORD="<changeme>" +BACKUP_DEST=/var/lib/backup BACKUP_FOLDERS=/etc\ /root\ /home +BACKUP_SERVER_WAIT=120 while [ -n "$1" ] do [ "$1" = "-c" ] && shift && BACKUP_CONFIG=$1 - [ "$1" = "-i" ] && shift && BACKUP_INIT=1 && BORG_PASSPHRASE=$1 + [ "$1" = "-i" ] && shift && BACKUP_INIT=1 shift done @@ -16,7 +18,7 @@ done [ -n "$BACKUP_OUTPUT" ] && exec > $BACKUP_OUTPUT 2>&1 if [ $EUID -ne 0 ] then - echo "`date`: Must be run as root" + echo "`date`: Must be run as root" > &2 exit 1 fi @@ -25,7 +27,7 @@ __cleanup() if [ -n "$BACKUP_MOUNTED" ] then umount $BACKUP_MOUNTPOINT - echo "Backup location mounted" + echo "Backup location unmounted" unset BACKUP_MOUNTED fi } @@ -38,7 +40,7 @@ if [ -n "$BACKUP_SERVER" ] then starttime=`date '+%s'` runningtime=0 - while [ $runningtime -le 120 ] + while [ $runningtime -le $BACKUP_SERVER_WAIT ] do if ping -c 1 $BACKUP_SERVER > /dev/null 2>&1 then @@ -53,7 +55,7 @@ then then echo "$BACKUP_SERVER reachable. Proceeding." else - echo "$BACKUP_SERVER NOT reachable. Exiting." + echo "$BACKUP_SERVER NOT reachable. Exiting." >&2 echo "Ending backup: `date`" exit -1 fi @@ -66,7 +68,7 @@ then echo "Backup location successfully mounted" BACKUP_MOUNTED=1 else - echo "Backup location mount FAILED. Confirm entry in /etc/fstab." + echo "Backup location mount FAILED. Confirm entry in /etc/fstab." >&2 echo "Quitting." echo "Ending backup: `date`" exit -2 @@ -75,11 +77,11 @@ fi if [ -n "$BACKUP_INIT" ] then - echo "$BORG_PASSPHRASE" > $BACKUP_PASSFILE - borg init --encryption=authenticated "$BACKUP_DEST" + BORG_PASSPHRASE=$BACKUP_PASSWORD \ + borg init --encryption=authenticated "$BACKUP_DEST" fi -BORG_PASSPHRASE=`cat $BACKUP_PASSFILE` borg create \ +BORG_PASSPHRASE=$BACKUP_PASSWORD borg create \ $BACKUP_DEST::`date '+%Y%m%d'` \ $BACKUP_FOLDERS 2>&1 diff --git a/backup.service b/backup.service @@ -3,4 +3,4 @@ Description=Backup service [Service] Type=simple -ExecStart=/root/bin/backup +ExecStart=/usr/lib/backup/backup diff --git a/config b/config @@ -1,6 +1,30 @@ +# vim: set ft=sh sts=4 sw=4 et: + +# A file to write stdout and stderr to. If running as a systemd service, then +# leaving this unset should have all output logged to the journal. #BACKUP_OUTPUT= + +# Will attempt to mount the following location before running the backup. +# NOTE: BACKUP_MOUNTPOINT MUST BE DEFINED IN /etc/fstab FOR THIS TO WORK!! #BACKUP_MOUNTPOINT= + +# To provide graceful handling of cases where backups are being stored on a +# remote server, the script checks for connectivity to BACKUP_SERVER before +# mounting BACKUP_MOUNTPOINT. If not backing up to a remote server, then leave +# this unset. #BACKUP_SERVER= -#BACKUP_PASSFILE= + +# The timeout (in seconds) to wait for server connectivity before giving up. +#BACKUP_SERVER_WAIT= + +# The backup password. +# NOTE: BECAUSE THIS IS STORED IN PLAINTEXT, THIS FILE SHOULD ONLY BE READABLE +# BY root! +#BACKUP_PASSWORD= + +# The full path of the folder to store the backup. (This folder will be created +# upon initialization if it doesn't already exist.) #BACKUP_DEST= + +# The folders to back up (each entry is recursive) #BACKUP_FOLDERS=