Guest User

Untitled

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