Advertisement
OldManRiver

mysql_backup.sh

May 21st, 2014
200
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. # Author: Nyle Davis Created 12-04-20
  3. # Purpose: Backup all MySQL DBs and tables
  4. # File: mysql_backup.sh
  5. # Run this with command:
  6. # bash ../Scripts/Backups/mysql_backup.sh (options)
  7. # Options:
  8. # 1=mode: daily, system
  9. # 2=path: alternate backup path, such as flash or network
  10. # Script is CRON capable
  11.  
  12. run_type=$1;
  13. if [ ${run_type} = "daily" ]; then
  14. flname="mysql_daily_("`eval date +%Y-%m-%d`").tgz";
  15. bkpath='/data/Backups';
  16. elif [ ${run_type} = "system" ]; then
  17. flname="mysql_system_("`eval date +%Y-%m-%d`").tgz";
  18. bkpath='/backups/Laptops/Aspire';
  19. else
  20. echo "No Run-Type option selected! ";
  21. fi
  22. if [ ${2} != "" ]; then
  23. bkpath="${2}";
  24. fi
  25.  
  26.  
  27. # Backup DBs
  28. dbuser='dbuser';
  29. dbpass='dbpass';
  30. dbpath='/usr/bin';
  31. dbopts='--add-drop-database --add-drop-table';
  32. cd ${bkpath};
  33. rm -f "${flname}";
  34. GZIP="$(which gzip)"
  35. ${dbpath}/mysqldump -u ${dbuser} -p${dbpass} ${dbopts} -A -C -f | $GZIP -9 > ${flname};
  36.  
  37. # May have to additionally manually backup the phpmyadmin option DB as sometime does not work correctly
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement