D
D
Dmitry2015-08-13 13:10:14
linux
Dmitry, 2015-08-13 13:10:14

How to organize convenient and simple (Files ZIP+MySQL Dump) automatic backup on the server?

There is a web server on Linux with Parallels Plesk Panel. There is a backup in the panel, but it is too complicated, works slowly, and stores files on the server in a bunch of incomprehensible folders in pieces.
Tell me how to set up automatic simple backup on the server (apparently via SSH and through some shell scripts / configs) that will work as follows:
1) Dumps MySQL ALL databases on the local server and packs them in ZIP (or TAR / GZIP, which works faster) archives to the /backup/current_date/mysql/ folder. Each database is a separate archive with its name.
2) Packs in a ZIP archive (or TAR/GZIP, which works faster) all subdirectories with files in the main directory where the site files are located ( /var/www/vhosts/domain.com/ ), EXCEPT for the error_docs, logs and httpdocs folders) into to /backup/current_date/www/ folder. Each folder in the main directory (these are domains) is a separate archive.
3) Packing archives should not load the server (and slow down the work of sites on it during execution), the degree of file compression is not so important, the main thing is that it works quickly and without load
4) Backup is performed every week at the specified time (for example, on Saturday at 00:00: 00) and can be started manually with the command
5) Sends me an email that the backup is finished with a log (what archives were created and their weight, execution time)
Tell me how to organize all this? (as I understand you need a simple script). Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Fedoseev, 2015-08-13
@martin74ua

[[email protected] ~]# cat /etc/cron.daily/backup_db.sh
#! /bin/bash -
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
MYSQL_SERVERS="srv01.db.com srv02.db. com"
DATE=`date +%Y.%m.%d-%R`
BACKUP_PATH="/mnt/backup/db"
BACKUP_EXT=".sql.bz2"
SAVE_DAYS="14"
DB_LOGIN="backup"
DB_PASS=" complex password here"
for srv in ${MYSQL_SERVERS}
do
if [ ! -d ${BACKUP_PATH}"/"${srv} ]; then
echo "Directory for ${srv} doesn't exist, creating..."
mkdir ${BACKUP_PATH}"/"${srv}
fi
for db in `mysql -h ${srv} -u${DB_LOGIN} -p${DB_PASS} -e 'show databases' | tail -n +2 | egrep -v "lost\+found|\.snap|information_schema|performance_schema"`
do
echo "Dumping database ${db} on ${srv}"
mysqldump -h ${srv} -u${DB_LOGIN} -p${ DB_PASS} --add-drop-database --add-drop-table --add-locks --create-options -e -F --flush-privileges -l -q -B ${db} | \
bzip2 -9c > "${BACKUP_PATH}/${srv}/${db}_${DATE}${BACKUP_EXT}"
echo
done
done
find ${BACKUP_PATH} -mindepth 1 -mtime +${SAVE_DAYS} -delete -exec echo "Deleting old file: " {} \;
the script has been spinning for a couple of years,
well how to configure privileges it is necessary to paint?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question