Previous class
Magento Database and Site Back Up
After successful installation let's set-up a database back-up and site back up system.
In this case we will use a 7 day rotating back-up system.
Open the crontab editor: Run crontab -e
to open the crontab file in a text editor. If it asks you to choose an editor, nano is a good choice for beginners.
Add a line to the crontab to backup the database: At the end of the file, add a line like this:
0 2 * * * mysqldump -u magento -p'password' magento_db | gzip > /home/backup/db_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz
This command will create a dump of the
magento_db
database using the magento
user and the password password
(replace with your actual database name, username, and password), compress it using gzip, and save it in the /home/backup
directory with a filename that includes the current date and time. The 0 2 * * *
at the beginning means the command will be run at 2am every day.Create a backup directory
sudo mkdir /home/backup
Add a line to the crontab to backup the home directory: Add another line like this:
30 2 * * * tar -czf /home/backup/home_$(date +\%Y\%m\%d\%H\%M\%S).tar.gz /home/magento
This command will create a compressed tarball of the
/home/magento
directory and save it in the /home/backup
directory with a filename that includes the current date and time. The command will be run at 2:30am every day.Save the crontab file and exit the editor: If you're using nano, you can do this by pressing
Ctrl+O
to save and Ctrl+X
to exit.Next class