This is often a task, but it is done quite simply!
Let's start:
1) muscle backup')
For this there is a very good utility “mysqldump”, it is part of the muscle. (if you use lampp then it is in “/ opt / lampp / bin / mysqldump”)
In general, we fill in the console about the following:
mysqldump –all-databases > /mysql.12.12.2008.dump
This command will save all databases to the “mysql.12.12.12.2008.dump” file at the root! actually write any convenient way! If you are not root, you need to specify a login / password with
–user login –password passwordGet ready, it can take a serious amount of time if the database is of a decent size.
A chip may not work if there are errors in any of the databases ...
By the way, you can approach the problem a little bit differently and don’t backup all the databases, but each separately, plus if there are errors in some of them, we will know which one is done like this:
databases=”$(mysql -Bse 'show databases')”
for db in $databases
do
mysqldump $db > $db.sql
done
2) backup filesIt's all easier, just archive the files, like this:
tar -czf some.tar.gz -C /home some
But again, it is much more convenient to pack the folder of each site into a separate archive, therefore:
names=`dir /home`
for i in $names
do
tar -czf $i.tar.gz -C /home $i
done
Well, in the end I got the following script:#!/bin/bash
date=`date +%d.%m.%Y_%H-%M`
mkdir /home/BACKUPS/$date
mkdir /home/BACKUPS/$date/DB
mkdir /home/BACKUPS/$date/DATA
databases=”$(mysql -Bse 'show databases')”
for db in $databases
do
if [ "$db" != "" ];
then
echo '——————'
echo 'START DUMPING “'$db'” DATABASE'
mysqldump $db > /home/BACKUPS/$date/DB/$db.sql
echo 'DB “'$db'” WAS SUCCESSFULLY DUMPED'
fi
done
names=`dir /home`
for name in $names
do
if [ "$name" != "BACKUPS" -a "$name" != "" ];
then
echo '——————'
echo 'START ARCHIVE “'$name'” FOLDER'
tar -czf /home/BACKUPS/$date/DATA/$name.tar.gz -C /home $name
echo 'FOLDER “'$name'” WAS SUCCESSFULLY ARCHIVED'
fi
done
All databases and site files are backed up in / home / BACKUPS / current date and time / DB for dumps and / home / BACKUPS / current date and time / DATA for archives