backups.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. #------------------------------------------------------------------------------
  3. # NOTE: Put the following into cron
  4. # 30 3 * * * /usr/local/bin/mysql_backup.sh
  5. #
  6. # ACKNOWLEDGEMENTS:
  7. # HTTPS://web.archive.org/web/20180510035437/http://www.linuxbrigade.com/back-up-all-of-your-mysql-databases-nightly/
  8. #------------------------------------------------------------------------------
  9. PathToGnusocial=${1:-""}
  10. BackupPath=./backups/
  11. StampVersion=`date -u +"%Y%m%dT%H%M%SZ"`
  12. BackupDir="${BackupPath}${StampVersion}"
  13. Hostname=`hostname | awk -F. '{print $1}'`
  14. # Echo back
  15. echo ${PathToGnusocial}
  16. echo ${BackupDir}
  17. echo ${Hostname}
  18. # Create the backup directory
  19. mkdir -p $BackupDir
  20. # Prompt for input
  21. read -p "DB_NAME:" DB_NAME
  22. read -p "DB_USER:" DB_USER
  23. mysqldump --user=$DB_USER --password --events --opt --single-transaction $DB_NAME \
  24. | gzip > "$BackupDir/mysqldump.gz"
  25. if [ "$?" -eq 0 ]
  26. then
  27. echo "Success"
  28. else
  29. echo "Mysqldump encountered a problem look in database.err for information"
  30. fi
  31. echo "Done with database."
  32. # Now backup the file and avatar directories
  33. # as well as the .htaccess and config.php
  34. tar -c ${PathToGnusocial}avatar/ \
  35. ${PathToGnusocial}file/ \
  36. ${PathToGnusocial}.htaccess \
  37. ${PathToGnusocial}config.php \
  38. | gzip > "$BackupDir/files.gz"
  39. echo "Done with files."