Last active
April 8, 2021 12:44
-
-
Save Systerr/60ea98801923d6f2508d to your computer and use it in GitHub Desktop.
Backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Execute :crontab -e | |
# add folow lines (create backup at 4-30 o'clock every day): | |
30 04 * * * /root/mysql-dump.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DAY=`date +%d` | |
KEEP_DAYS=3 | |
DIR=$(($DAY % $KEEP_DAYS)) | |
tar -chvpzf /var/backup/files/$DIR.tar.gz /var/www |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DIR=`date +%d` | |
DEST=/var/backups/mongo/$DIR | |
mkdir $DEST | |
mongodump -o $DEST | |
tar -cvzf /var/backups/mongo/$DIR.tar.gz $DEST | |
rm -r $DEST | |
cp /var/backups/mongo/$DIR.tar.gz /mnt/s3/mongo/$DIR.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DIR=`date +%d-%H` | |
DEST=/var/backups/mongo/$DIR | |
mkdir $DEST | |
mongodump -o $DEST | |
tar -cvzf /var/backups/mongo/$DIR.tar.gz $DEST | |
rm -r $DEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
TIMESTAMP=$(date +"%F") | |
BACKUP_DIR="/backup/$TIMESTAMP" | |
MYSQL_USER="backup" | |
MYSQL=/usr/bin/mysql | |
MYSQL_PASSWORD="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 --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DIR=`date +%d` | |
mysqldump -uroot -pSECRETPASSWORD -h127.0.0.1 --all-databases | gzip > /var/backups/mysql/$DIR.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DIR=`date +%d` | |
mysqldump -uroot -pSECRETPASSWORD -h127.0.0.1 --all-databases --single-transaction | gzip > /var/backups/mysql/$DIR.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DIR=`date +%d` | |
pg_dumpall | gzip > /var/backups/pgsql/$DIR.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment