Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Author: Nyle Davis Created 14-07-17
- # Purpose: Backup all MySQL DBs and tables as dump
- # File: mysql_dump.sh
- # Modified: 16-05-12 By: NED
- # Fixed errors and moved rm code inside if statement
- # Run this with command:
- # bash ../Scripts/Backups/mysql_dump.sh (options)
- # Options:
- # 1=mode: backup, restore
- # Script is CRON capable
- if [[ "${1}" != "" ]]; then
- run_type=${1};
- else
- run_type="backup";
- fi
- defdir='/home/files/Dropbox/backups/';
- HSTNM=$(hostname -f);
- if [[ ${2} != "" ]]; then
- bkpath=$2;
- else
- mkdir /backups/mysql/;
- bkpath="/backups/mysql/";
- chown -R ndavis:users ${bkpath};
- chmod -R 775 ${bkpath};
- # bkpath="${defdir}MySQL-DB/";
- fi
- #flname="mysql_dump_${HSTNM}_("`eval date +%Y-%m-%d`").tgz";
- flname="mysql_dump_Aspire-LT-2016-05-11.tar.gz";
- #echo "RT=> ${run_type} HST=> ${HSTNM} BP=> ${bkpath} FL=> ${flname}";
- dbuser='ndavis';
- dbpass='nomened1497';
- dbpath='/usr/bin';
- GZIP="$(which gzip)";
- infile=${bkpath}${flname};
- if [[ ${run_type} == "restore" ]]; then
- # Restore DBs
- echo "Running MySQL compressed file restore!";
- echo "InFile=> ${infile}";
- $GZIP -9 < ${infile} | ${dbpath}/mysql -u ${dbuser} -p${dbpass};
- # ${dbpath}/mysql --user=${dbuser} --password=${dbpass} < ${infile};
- # tar -xzOf ${infile} | ${dbpath}/mysql --user=${dbuser} --password=${dbpass};
- fi
- if [[ ${run_type} == "backup" ]]; then
- rm -f "${bkpath}${flname}";
- # dbopts='--add-drop-database --add-drop-table --events -A -C -f';
- dbopts='-A -E -C -f';
- # Backup DBs
- echo "Running MySQL compressed file backup!";
- echo "OutFile=> ${infile}";
- ${dbpath}/mysqldump -u ${dbuser} -p${dbpass} ${dbopts} | $GZIP -9 > ${infile};
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement