2018-12-08 00:30:04 +01:00
|
|
|
#!/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
|
|
|
|
# "
|
|
|
|
#
|
|
|
|
##################################################################
|
|
|
|
|
|
|
|
|
2018-12-16 17:30:44 +01:00
|
|
|
if [ -z $1 ]; then
|
|
|
|
echo "usage: dobackup FILE"
|
|
|
|
echo "need file with backup instructions"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-12-08 00:30:04 +01:00
|
|
|
name=`basename $1`
|
|
|
|
source $1
|
|
|
|
|
|
|
|
timestamp=`date +"%Y%m%d-%H%M"`
|
|
|
|
dest="$HOME/backups/$name-$timestamp"
|
2022-09-19 11:20:50 +02:00
|
|
|
errfile="$name-$timestamp.errs"
|
|
|
|
|
|
|
|
touch errfile
|
2018-12-08 00:30:04 +01:00
|
|
|
|
|
|
|
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"
|
2022-09-19 11:20:50 +02:00
|
|
|
$fullcommand 2>>"$errfile"
|
2018-12-08 00:30:04 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "$postcommand"
|
|
|
|
eval ${postcommand}
|
2022-09-19 11:20:50 +02:00
|
|
|
|
|
|
|
cat "$errfile"
|