Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # myugan59@gmail.com
  4.  
  5. # CRED
  6. DB_USER="user"
  7. DB_PASS="user"
  8. DB_NAME="dbname"
  9.  
  10. # PATH/DIR
  11. SRCDIR="/path/to/backups"
  12. EXPDIR="$SRCDIR/$DB_NAME_$(date +"%H%M-%d-%m-%Y").sql"
  13.  
  14. # Dump db to local
  15. mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $EXPDIR
  16.  
  17. # Compress db
  18. tar -zcvf $EXPDIR.tar.gz $EXPDIR
  19.  
  20. # Cleanup db after 30 days
  21. find $SRCDIR -maxdepth 1 -type f -iname '*.sql' -mtime +30 -print0 | xargs -0 rm -f
  22. find $SRCDIR -maxdepth 1 -type f -iname '*.tar.gz' -mtime +30 -print0 | xargs -0 rm -f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement