Backup mysql from docker
Nov 19, 2021
- Create backup.sh
#!/bin/bash
# Set the backup directory
BACKUP_DIR=”/opt/backup”
mkdir -p $BACKUP_FILE
# Set the MySQL container name or ID
CONTAINER_NAME=”mysql”
# Set the MySQL database name
DATABASE_NAME=”dbName”
# Set the backup file name
BACKUP_FILE=”$BACKUP_DIR/$(date +”%d-%m-%y-%H%M%S.sql.gz”)”
# Run the backup command
docker exec $CONTAINER_NAME sh -c “exec mysqldump -u user -pPassword $DATABASE_NAME” > $BACKUP_FILE
#Copy file sql to google drive
rclone copy “$BACKUP_FILE” gDrive:/BACKUP-DATABASE/`date ‘+%Y’`/`date ‘+%m’`/
2. Set Crontab
*กรณีที่ต้องการ Copy ไปที่ Google Drive
https://thanaroj09.medium.com/gdrive-backup-data-to-google-drive-from-linux-448295659210