Godleydemon

server-backup.sh

Dec 1st, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.52 KB | None | 0 0
  1. ##prompt for user input and output##
  2. ##answers to variables             ##
  3. read -p 'servername: ' -e server
  4. read -p 'tarname: ' -e tarname
  5. read -p 'server destination: ' -e destination
  6.  
  7.  
  8. ##main script function##
  9. sc_function ()
  10. {
  11. ##save server to make sure its completely new##
  12. service mc$server command save-all
  13.  
  14. ##tar up server that needs tarred##
  15. tar -cvf $tarname.tar /home/$server/*
  16.  
  17. ##copy paste file from local server to remote server##
  18. scp $tarname.tar root@"$destination":/var/www/$tarname.tar
  19.  
  20. ##remove tarred file for cleanup purposes##
  21. rm /home/serverconfigs/deployscripts/$tarname.tar
  22.  
  23. ##finish her up##
  24. echo "server $server backed up and moved to $destination /var/www/ "
  25. echo "You can now download the backup at http://$destination/$tarname.tar"
  26. }
  27. ##loop for a yes or no answer##
  28. while true; do
  29.     echo "server $server will be backed up into $tarname.tar"
  30.     echo "will transfer $tarname.tar to $destination /var/www/"
  31.     echo "Then remove $tarname.tar from /home/serverconfigs/deployscripts/"
  32.     ##read answer to a variable named yn##
  33.     read -p "Is this correct [y/n]" yn
  34.     case $yn in
  35.     ##if variable equals Y or y then do the following##
  36.     ##you can run multiple functions on this line,   ##
  37.     ##will execute in order, break is to end script  ##
  38.     ##if break isn't there the script will repeat    ##
  39.     [Yy]* ) sc_function; break;;
  40.     ##if variable equals N or n then just exit script##
  41.     [Nn]* ) exit ;;
  42.     ##if anything else is typed prompt echo then repeat loop##
  43.     * ) echo "please answer y or n.";;
  44.     esac
  45. done
Advertisement
Add Comment
Please, Sign In to add comment