Guest User

Untitled

a guest
Apr 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ################ Global Configs ################
  4. BACKUPDRIVE='/dev/sdb1/'
  5. MOUNTPOINT='/backup'
  6. MYSQLPASSWORD='mysqlpassword'
  7. TEMPPATH='/backup/temp'
  8. ###############################################
  9.  
  10. ############## Local Backup Configs ###########
  11. DAILYBACKUPS=1
  12. DAILYPATH='/backup/ElectServer01/Automated/Daily/'
  13. DAYSTOKEEP=7
  14.  
  15. WEEKLYBACKUPS=1
  16. WEEKLYPATH='/backup/ElectServer01/Automated/Weekly/'
  17. WEEKSTOKEEP=4
  18.  
  19. MONTHLYBACKUPS=1
  20. MONTHLYPATH='/backup/ElectServer01/Automated/Monthly/'
  21. MONTHSTOKEEP=12
  22. ###############################################
  23.  
  24. ############ Remote Backup Configs ############
  25. REMOTEBACKUPS=1
  26. REMOTEUSER='ElectServer01'
  27. REMOTESERVER='ElectServer01'
  28. REMOTEPATH='ElectServer01'
  29. ###############################################
  30.  
  31. ########## Backup To The Temp Folder ##########
  32. mkdir $TEMPPATH
  33. cp -dRu --preserve=ownership /var/www $TEMPPATH/Apache
  34. mkdir $TEMPPATH/MySQL
  35. mysqldump --all-databases --password=$MYSQLPASSWORD > $TEMPPATH/MySQL/dump.mysql
  36. mkdir $TEMPPATH/OpenLDAP
  37. slapcat -v -l $TEMPPATH/OpenLDAP/dump.ldif
  38. mkdir $TEMPPATH/SAMBA
  39. cp -dRu --preserve=ownership /etc/samba/smb.conf $TEMPPATH/SAMBA/smb.conf
  40. mkdir $TEMPPATH/ProFTPD
  41. cp -dRu --preserve=ownership /etc/proftpd/proftpd.conf $TEMPPATH/ProFTPD
  42. cp -dRu --preserve=ownership /etc/proftpd/ldap.conf $TEMPPATH/ProFTPD
  43. cp -dRu --preserve=ownership /etc/proftpd/modules.conf $TEMPPATH/ProFTPD
  44. cp -dRu --preserve=ownership /home $TEMPPATH/Home
  45. ###############################################
  46.  
  47. ######### Do daily backups if needed ##########
  48. if [DAILYBACKUPS=1]; then
  49.     cp $TEMPPATH $DAILYPATH/$(date +%d-%m-%Y)/
  50. fi
  51. ###############################################
  52.  
  53. ### Do weekly backups if needed on a Sunday ###
  54. if [WEEKLYBACKUPS=1]; then
  55.     if [ `date +%a` = Sun ]; then
  56.         cp -dRu --preserve=ownership $TEMPPATH $WEEKLYPATH/$(date +%d-%m-%Y)/
  57.     fi
  58. fi
  59. ###############################################
  60.  
  61. ### Do monthly backups if needed on the 1st ###
  62. if [MONTHLYBACKUPS=1]; then
  63.     if [ `date +%d` = 01 ]; then
  64.         cp -dRu --preserve=ownership $TEMPPATH $MONTHLYPATH/$(date +%d-%m-%Y)/
  65.     fi
  66. fi
  67. ###############################################
  68.  
  69. ########## Do remote backup if needed #########
  70. if [REMOTEBACKUPS=1]; then
  71.     rsync –ave ssh $TEMPPATH $REMOTEUSER@$REMOTESERVER:$REMOTEPATH
  72. fi
  73. ###############################################
  74.  
  75. ############ Delete the Temp Files ############
  76. rm -R $TEMPPATH
  77. ###############################################
  78.  
  79. ########### Remove Older Daily Backups ########
  80. find $DAILYPATH -type d -mtime +$DAYSTOKEEP
  81. ###############################################
  82.  
  83. ########## Remove Older Weekly Backups ########
  84. find $WEEKLYPATH -type d -mtime +$(($WEEKSTOKEEP*7))
  85. ###############################################
  86.  
  87. ########## Remove Older Monthly Backups #######
  88. find $WEEKLYPATH -type d -mtime +$(($MONTHSTOKEEP*31))
  89. ###############################################
Add Comment
Please, Sign In to add comment