Last active
May 22, 2018 19:11
-
-
Save vpnwall-services/8d0ae258e170ff9284b530aa9ad03018 to your computer and use it in GitHub Desktop.
[BackupRestore] Backup and restore functions #linux #script #backup #rsync #menu #array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#PUT DOMAIN NAMES IN THESES VAR | |
domainnames=("example.com" "example.net") | |
ctrl_c(){ | |
echo -e "quitting ..." | |
exit 130; | |
} | |
startbackup(){ | |
today=`date '+%Y_%m_%d__%H_%M_%S'` | |
filename=backup-$domain-$today.rsync | |
mkdir $PWD/$filename | |
echo -e "Login in ..." | |
rsync -aAXv --progress --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} root@$domain:/ $PWD/$filename | |
} | |
startrestore(){ | |
today=`date '+%Y_%m_%d__%H_%M_%S'` | |
filename=$providedfilename.rsync | |
rsync -aAXv --progress --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / $PWD/$filename | |
} | |
loopmode(){ | |
trap ctrl_c INT | |
for domain in "${domainnames[@]}" | |
do | |
echo -e "Backup in progress for $domain ..." | |
trap ctrl_c INT | |
startbackup "$domain" && echo -e "Backup done" | |
done | |
} | |
passtotmux() { | |
_FUNC_TO_PASS="${1}" | |
_IFS_BACKUP="${IFS}" | |
IFS=$'\n' | |
for i in $(type ${_FUNC_TO_PASS} | tail -n +2); do | |
tmux send-keys "${i}" C-m | |
done | |
IFS="${_IFS_BACKUP}" | |
} | |
menu(){ | |
options=("Backup (1)" "Restore (2)" "Exit (3)") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Backup (1)") | |
loopmode | |
;; | |
"Restore (2)") | |
;; | |
"Exit (3)") | |
break | |
;; | |
*) echo -e "Invalid option" ; clear ; menu; | |
esac | |
done | |
} | |
tmux new-session -A -d -s Backup-Restore 'bash backuprestore.sh menu' | |
tmux at | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment