Skip to content

Instantly share code, notes, and snippets.

@tdtgit
Created June 15, 2017 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdtgit/a1317ebabe33fc885d5f9dc128c28974 to your computer and use it in GitHub Desktop.
Save tdtgit/a1317ebabe33fc885d5f9dc128c28974 to your computer and use it in GitHub Desktop.
Backup nhanh toàn bộ CSDL MySQL
#!/bin/bash
TIMESTAMP=$(date +"%F-%H-%M")
BACKUP_DIR="/root/backup/$TIMESTAMP"
MYSQL_USER="root"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD=<MYSQL_PASSWORD_GO_HERE>
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p "$BACKUP_DIR/sql"
echo "Starting Backup Database";
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"`
for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz"
done
echo "Finished";
echo '';
@tdtgit
Copy link
Author

tdtgit commented Jun 15, 2017

Cách sử dụng

  1. Upload lên thư mục /root/
  2. Thay <MYSQL_PASSWORD_GO_HERE> thành mật khẩu tài khoản root của MySQL
  3. Chạy lệnh chmod +x mysql_backup.sh
  4. Chạy ./mysql_backup.sh và đợi kết quả

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment