×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Bash
Posted by: Massimo Zappino
Added: Sep 14, 2012 7:57 AM
Modified: Aug 11, 2017 2:35 PM
Views: 65
  1. # install s3cmd version 1.0.0-4
  2. # http://s3tools.org/debian-ubuntu-repository-for-s3cmd
  3. wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | apt-key add -
  4. wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
  5. apt-get update && apt-get install s3cmd
  6.  
  7. # configure s3cmd with your Amazon keys
  8. s3cmd --configure
  9.  
  10. ###############################
  11. BASH SCRIPT
  12. ###############################
  13. #!/bin/bash
  14.  
  15. DATABASE="my_database";
  16. USERNAME="my_username"
  17. PASSWORD="my_password"
  18. HOSTNAME="localhost"
  19. BUCKET="my_bucket"
  20.  
  21. DUMPFILE="$DATABASE"_$(date +"%Y%m%d").dmp
  22. GZFILE="$DATABASE"_$(date +"%Y%m%d").gz
  23.  
  24. # Dump Database
  25. mysqldump -u $USERNAME -h $HOSTNAME -p$PASSWORD $DATABASE > $DUMPFILE
  26.  
  27. cat $DUMPFILE | gzip > $GZFILE;
  28. MONTH=$(date +"%Y-%m")
  29. s3cmd put $GZFILE s3://$BUCKET/my_db_backup_dir/$MONTH/$GZFILE
  30.  
  31. rm $DUMPFILE $GZFILE;
  32.