public
Last active

Database maintenance from console.

  • Download Gist
MYDB.cnf
1 2 3 4
[client]
host=
user=
password=
backupDB.sh
Shell
1 2 3 4 5 6 7 8 9
#!/bin/bash
# Backup database from console
DATABASE=
DEFAULTS_FILE=$DATABASE.cnf
BACKUP_DIR=
LOGS_DIR=
 
DB_OUT_FILENAME=$DEFAULTS_FILE-`date +\%Y\%m\%d`.sql.gz
mysqldump --defaults-extra-file=$DEFAULTS_FILE $DATABASE 2>> $LOGS_DIR/$DATABASE.log | gzip - > $BACKUP_DIR/$DB_OUT_FILENAME
truncateTables.sh
Shell
1 2 3 4 5 6
#!/bin/bash
# Truncate database tables from console
DATABASE=
DEFAULTS_FILE=$DATABASE.cnf
 
mysql --defaults-extra-file="$DEFAULTS_FILE" -Nse 'show tables' $DATABASE | while read table; do mysql --defaults-extra-file="$DEFAULTS_FILE" -e "truncate table $table" $DATABASE; done

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.