add backup script
This commit is contained in:
parent
ced7a44180
commit
c811247bbc
53
dobackup
Executable file
53
dobackup
Executable file
|
@ -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}
|
Loading…
Reference in New Issue
Block a user