-
-
Save sutlxwhx/7355dd1a65ea2a0889fb8dee6059283e to your computer and use it in GitHub Desktop.
| #!/usr/bin/env bash | |
| # | |
| TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") | |
| # | |
| BACKUP_DIR="/backup/$TIMESTAMP" | |
| # | |
| MYSQL_USER="" | |
| # | |
| MYSQL=/usr/bin/mysql | |
| # | |
| MYSQL_PASSWORD="" | |
| # | |
| MYSQLDUMP=/usr/bin/mysqldump | |
| # | |
| mkdir -p "$BACKUP_DIR/mysql" | |
| # | |
| databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` | |
| # | |
| for db in $databases; do | |
| # | |
| $MYSQLDUMP --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db > "$BACKUP_DIR/mysql/$db.sql" | |
| # | |
| rclone copy $BACKUP_DIR remote:$BACKUP_DIR | |
| done |
Why not using "rclone rcat" ?
https://rclone.org/commands/rclone_rcat/
I am not sure rcat behaves the same way as copy while processing files and folders
I have 2 sugestions
first, let give some compression to file
$MYSQLDUMP --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db.sql.gz"
and copy only that file
rclone copy "$BACKUP_DIR/$db.sql.gz" $REMOTE:$BACKUP_DIR
I try and get error
backup_db_new.sh: 23: /backup_db_new.sh: Syntax error: word unexpected (expecting "do")
For me I use SSH to remotely create the backups which gets stored locally.
ssh -C remoteuser@remote_host mysqldump -u MYSQL_USER -p'MYSQL_PASSWORD' --all-databases | gzip -c | cat > backup.sql-date +%Y%m%d%H%M%S.gz
This way I don't have to deal with rsync or rclone. I use --all-databases to backup all databases. You can specify which database if you want.
how to exclude some database?
Why not using "rclone rcat" ?
https://rclone.org/commands/rclone_rcat/