Guest User

Untitled

a guest
Mar 14th, 2019
106
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.  
  4. # CRED
  5. DB_USER="user"
  6. DB_PASS="user"
  7. DB_NAME="dbname"
  8.  
  9. # PATH/DIR
  10. SRCDIR="/path/to/backups"
  11. EXPDIR="$SRCDIR/$DB_NAME_$(date +"%H%M-%d-%m-%Y").sql"
  12.  
  13. # Dump db to local
  14. mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $EXPDIR
  15.  
  16. # Compress db
  17. tar -zcvf $EXPDIR.tar.gz $EXPDIR
  18.  
  19. # Cleanup db after 30 days
  20. find $SRCDIR -maxdepth 1 -type f -iname '*.sql' -mtime +30 -print0 | xargs -0 rm -f
  21. 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