Advertisement
Guest User

Backup Everything

a guest
Dec 11th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.58 KB | None | 0 0
  1. echo Welcome to this backup script on $(date).
  2. sleep 1
  3. echo "Written by XXXX from XXXX (c) 2016"
  4. sleep 5
  5. ##################################
  6. # This is the first state of the program, here we will compress all individual webspace folders
  7. ##################################
  8. echo First we are going to create rar files for each domain.
  9. cd /
  10. cd var
  11. cd www
  12. cd vhosts
  13. echo We are now in the right directory, now rar will be executed... This will take a long time.
  14. sleep 5
  15. #for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder"; done
  16. for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder" > /dev/null 2>&1 ; echo Files for domain "${folder%/}" have been compressed. ; done ;
  17. echo Process complete. Moving files to temp space.
  18. mv *.rar /root/backup/files
  19. echo Moving completed.
  20. ##################################
  21. # This is the second state of the program where mail is backupped
  22. ##################################
  23. echo "We will now backup the mail using about the same method (using rar)."
  24. cd /
  25. cd var
  26. cd qmail
  27. cd mailnames
  28. echo We are now in the right directory, now rar will be executed... This will take a long time.
  29. sleep 5
  30. #for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder"; done
  31. for folder in */; do rar a -m0 -r "${folder%/}.mail.rar" "$folder" > /dev/null 2>&1 ; echo Mail for domain "${folder%/}" has been compressed. ; done ;
  32. echo Process complete. Moving files to temp space.
  33. mv *.rar /root/backup/mail
  34. echo All mail has been archived in the right directory. Proceeding to database backup..
  35. echo Changing working directory.
  36. ##################################
  37. # The third state, we are going to backup mysql
  38. ##################################
  39. cd /
  40. cd root
  41. cd backup
  42. cd sql
  43. echo Working directory changed.
  44. echo Commencing MySQL backup...
  45. # Optional variables for a backup script
  46. MYSQL_USER="admin"
  47. MYSQL_PASS=`cat /etc/psa/.psa.shadow`
  48. #BACKUP_DIR=/root/backup/sql/$(date +%F);
  49. BACKUP_DIR=/root/backup/sql/
  50. test -d "$BACKUP_DIR" || mkdir -p "$BACKUP_DIR"
  51. # Get the database list, exclude information_schema
  52. for db in $(mysql -B -s -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases' | grep -v information_schema)
  53. do
  54.   # dump each database in a separate file
  55.   echo Making backup of database "$db".
  56.     mysqldump -u $MYSQL_USER --password=$MYSQL_PASS "$db" | gzip > "$BACKUP_DIR/$db.sql.gz"
  57. done
  58. echo Done backupping all databases.
  59. ##################################
  60. # The forth state, we are going to move the files, mail and sql folder to the upload dir
  61. ##################################
  62. echo Moving files to upload directory..
  63. BACKUP=/root/backup/upload/$(date +%F);
  64. mkdir $BACKUP
  65. echo Moving webspace rar files...
  66. mv /root/backup/files/* $BACKUP
  67. echo Done moving webspace rar files
  68. echo Moving mail rar files...
  69. mv /root/backup/mail/* $BACKUP
  70. echo Done moving mail rar files
  71. echo Moving database files...
  72. mv /root/backup/sql/* $BACKUP
  73. echo Done moving database files
  74. ##################################
  75. # The fifth state, uploading and copying
  76. ##################################
  77. echo Commencing FTP upload. This will take a long time
  78. ncftpput -R -v -u "XXXX" -p "XXXX" 83.162.184.234 /home/trustinternet.nl/Backup $BACKUP
  79. echo Upload complete.
  80. echo tranferring files to Strato cloud backup area $BACKUP please wait
  81. cp -R -v /root/backup/upload/* /private-backup
  82. echo Local copy completed.
  83. echo All done, cleaning up.
  84. ##################################
  85. # The sixth state, we remove the files we created, because the files are now safe off premises.
  86. ##################################
  87. rm -rf /root/backup/upload/*
  88. echo Backup finished on $(date).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement