From c811247bbc04e4e7ee22460e225c2ab8ae3594a6 Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 8 Dec 2018 00:30:04 +0100 Subject: [PATCH] add backup script --- dobackup | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 dobackup diff --git a/dobackup b/dobackup new file mode 100755 index 0000000..f479f02 --- /dev/null +++ b/dobackup @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +################################################################## +# does backups (duh.) with rsync, either local or remote via ssh +# sources the file given as first parameter and acts accordingly +# example file: +# +# precommand="echo Yippee ki-yay" +# postcommand="echo done" +# remote=true +# sshUserHost="foo@bar.org" +# +# files=" +# /etc +# /some/other/folder +# /some/file.sh +# " +# +################################################################## + + +name=`basename $1` +source $1 + +timestamp=`date +"%Y%m%d-%H%M"` +dest="$HOME/backups/$name-$timestamp" + +if [ "$remote" = true ]; then + if [ -z "$sshUserHost" ]; then + echo "ssh data not complete, needs sshUserHost" + exit 1 + else + command="rsync -avzR -e ssh $sshUserHost:" + fi +else + command="rsync -avR " +fi + +echo "$precommand" +eval ${precommand} + +for file in $files; do + fullcommand="$command$file $dest" + echo "$fullcommand" + if [ "$remote" = true ]; then + $fullcommand + else + $fullcommand || exit 1 + fi +done + +echo "$postcommand" +eval ${postcommand}