fbpx

Magento / Web Apps

Magento 1.x backup script

by , , revisited on


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Backups are important. The following backup script will allow you to backup both Magento 1.x files and database. It doesn’t require hard coding database details. The script is smart enough to extract those details from Magento configuration files. This is quite flexible.

Another nice feature of the script is having the backups running at both low CPU and IO priority. Your store will keep running as smoothly as always. For that, we make use of ionice and nice utilities found on all major Linux distros by default.

Here is how to setup backups in cron:

@daily /bin/bash /usr/local/bin/backup-magento.sh /var/www/html /var/backups/daily 3
@weekly /bin/bash /usr/local/bin/backup-magento.sh /var/www/html /var/backups/daily 21
@monthly /bin/bash /usr/local/bin/backup-magento.sh /var/www/html /var/backups/daily 60

Now you have 3 slots of backups with difference frequency: one backup will 24hrs freshness, one for weekly, and one for monthly. The previous backups will be automatically cleaned every time a slot is run.

  1. Lewis Seals

    Thanks for the script. God bless you!

    Reply
  2. Lewis Seals

    I have been using this script and it works great but why do you exclude the var and the includes folder? –exclude=var –exclude=includes * .htaccess Do you have to add these back after restore or am I missing something. God bless you!

    Reply
    • Danila Vershinin

      Hi Lewis,

      The var and includes folders are excluded because they contain nothing but transient data (logs, error reports and Magento compiler PHP files). However, I have updated the script now in regards with handling these two areas better.

      For /includes: Compiler config (/includes/config.php) is now always backed up. Most common case is when the compiler is disabled, but in case it is (script detects this), then the script will backup /includes/src as well.

      For /var: The script backups empty /var now. When you restore a backup, Magento should be able to re-create whatever directory structure it needs inside /var (provided that you’re running it with correct user / chmod. E.g. var/cache, var/report, etc.)

      Reply
  3. Lewis Seals

    Awesome Danila, God bless you!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.