BASH 34
[debian] Mount network drives (fstab), cron, delete-cycle By micha on 20th August 2018 04:47:36 PM
  1. /etc/fstab
  2. //192.168.2.240/aliaz-Server2/aliaz\040GmbH/Webentwicklung/_SERVER_web-server_auto-backup /mnt/web_ext_backups cifs username=backup_user,password={PASSWORD},iocharset=utf8,sec=ntlm 0 0
  3.  
  4. //Read fstab and remount
  5. mount -a
  6.  
  7. //Mount a network drive temporary
  8. mount -t cifs -o username=backup_user,password=hv7t64g9 //192.168.2.69/aliaz-Server2/aliaz\ GmbH/Webentwicklung/_SERVER_web-server_auto-backup
  9.  
  10.  
  11. //MySQL Backup -All DBs
  12. Datum=`/bin/date '+%Y-%m-%d---%H-%M-%S'` && mysqldump -uroot -phv7t64g9 --all-databases > /mnt/data/Webserver/SQL/sql_$Datum.sql
  13.  
  14. //Delete SQL Files older than 10 days
  15. /usr/bin/find /mnt/data/Webserver/SQL -type f -mtime +10 | xargs rm -rf
  16.  
  17.  
  18. //Find Files newer than 1 day
  19. find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime -1
  20.  
  21.  
  22. //Copy the generated local backup file (newer than 1 day) from debian linux maschine to the mounted network drive
  23. find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime -1 -exec cp -t /mnt/web_ext_backups/ {} \;
  24. find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime -1 | xargs cp -t /mnt/web_ext_backups/
  25.  
  26.  
  27. //Do the same for our SQL backup file
  28. find /mnt/data/Webserver/SQL/* -maxdepth 0 -type f -mtime -1 -exec cp -t /mnt/web_ext_backups/ {} \;
  29. find /mnt/data/Webserver/SQL/* -maxdepth 0 -type f -mtime -1 | xargs cp -t /mnt/web_ext_backups/
  30.  
  31.  
  32. //Remove (delete) Backup files older than 2 month from backup_dir
  33. find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime +60 | xargs rm -rf
  34.  
  35.  
  36. //Remove older files than 1 day on external mounted drive (NAS)
  37. find /mnt/web_ext_backups/* -maxdepth 0 -type f -mtime +1 | xargs rm -rf
  38.  
  39.  
  40. //Das Backup des kompletten htdocs Verzeichnisses wird über das Webmin Modul "Filesystem Backup" erstellt.
  41. Backup Format: Unix TAR
  42. Backup Directory: /var/www/html
  43. Backup to: /mnt/data/Webserver/html_%A.tar.gz
  44.  
  45.  
  46.  
  47. /var/spool/cron/crontabs
  48. @daily Datum=`/bin/date '+\%Y-\%m-\%d---\%H-\%M-\%S'` && mysqldump -uroot -phv7t64g9 --all-databases > /mnt/data/Webserver/SQL/sql_$Datum.sql #MySQL Backup -All DBs
  49. @weekly /usr/bin/find /mnt/data/Webserver/SQL -type f -mtime +10 | xargs rm -rf #Delete SQL Files older than 10 days
  50. @daily find /mnt/data/Webserver/SQL/* -maxdepth 0 -type f -mtime -1 | xargs cp -t /mnt/web_ext_backups/ #Copy the generated local backup file (SQL) (newer than 1 day) from debian linux maschine to the mounted network drive
  51. @daily find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime -1 | xargs cp -t /mnt/web_ext_backups/ #Copy the generated local backup file (tar.gz) (newer than 1 day) from debian linux maschine to the mounted network drive
  52. @daily find /mnt/web_ext_backups/* -maxdepth 0 -type f -mtime +1 | xargs rm -rf #Delete older files than 1 day on external mounted drive (NAS)
  53. @weekly find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime +60 | xargs rm -rf #Delete Backup-Cycle files older than 2 month
  54.  
  55. ---
  56.  
  57. @daily Datum=`/bin/date '+\%Y-\%m-\%d---\%H-\%M-\%S'` && mysqldump -uroot -phv7t64g9 --all-databases > /mnt/data/Webserver/SQL/sql_$Datum.sql | echo "Job completed by debian-aliaz: $Datum" | mail -s "[debian-aliaz] Cronjob - MySQL dump completed" admin@aliaz.de #MySQL Backup -All DBs
  58. @weekly /usr/bin/find /mnt/data/Webserver/SQL -type f -mtime +10 | xargs rm -rf #Delete SQL Files older than 10 days
  59. 0 1 * * * find /mnt/data/Webserver/SQL/* -maxdepth 0 -type f -mtime -1 | xargs cp -t /var/www/sql/ | echo "Job completed by debian-aliaz: Copy the generated local backup file (SQL) (newer than 1 day) from debian linux maschine backup dir to web directory for rsync service" | mail -s "[debian-aliaz] Cronjob - SQL copied to web directory for rsync service" admin@aliaz.de #Copy the generated local backup file (SQL) (newer than 1 day) from debian linux maschine backup directory to web directory for rsync service
  60. @weekly find /mnt/data/Webserver/* -maxdepth 0 -type f -mtime +60 | xargs rm -rf #Delete Backup-Cycle files older than 2 month
  61. 15 1 * * * find /var/www/sql -type f -mtime +1 | xargs rm -rf | echo "Job completed by debian-aliaz:" | mail -s "[debian-aliaz] Cronjob - MySQL cleanup for rsync" admin@aliaz.de
  62. 30 1 * * * rsync -ahv --delete --no-o --no-g --no-p --log-file=/var/www/html/rsync.log --password-file=/root/rsync_pass /var/www/ backup_user@192.168.2.240::Aliaz-Webdev/debian-aliaz-linux-01/ #Sync webserver (/var/www) to NAS01-HA #Sync webserver (/var/www) to NAS01-HA #Sync webserver (/var/www) to NAS01-HA

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.