Views: 11270
Last Modified: 09.03.2023

Scheduled backups

Often, when deploying project, based on BitrixVA/BitrixEnv, a backup copy for the project is required.

Automatic backup feature for the site and the database is available in BitrixVA/BitrixEnv. Backup will be created as per schedule in the .tar.gz archive format and recorded in the directory /home/bitrix/backup/archive/.

This method has both advantages and disadvantages, compared to Bitrix24 products built-in backup copy mechanism:

  • Advantages: higher creation speed for backup copy and independence from project performance.
  • Disadvantages: backup copy cannot be created for files, stored in Cloud-storage drives.

Creating a schedule

To create scheduled automatic backup copy via BitrixVA/BitrixEnv tools:

  • Select item 6. Manage sites in the pool > 6. Change backup settings on site in the Virtual Appliance settings.
  • Select host name from the list and confirm the option to change of automatic backup schedule:

  • Select period and hour for the start of automatic backup:

    If more detailed configuration for backup is required, command line utility can be used:

    /opt/webdir/bin/bx-sites -a backup -d dbcp --enable --minute=10 --hour=18 --day=any --month=any --weekday=any

    Note: How to configure the correct time in BitrixVA/BitrixEnv, see here.

  • After this step, the work of configuration wizard is finished. The task to create backup copy for project is added in Cron (/etc/crontab).

    Backup is created for kernel (site type kernel and ext_kernel) and its all links, if such exist. To perform backup, the task is created in crontab-file. For example:

    10 22 * * * bitrix /opt/webdir/bin/ sitemanager0 /home/bitrix/backup/archive

    As the first option, DB name is added; second option indicates catalogue, where the archive will be created.

    As a result, the following type of archive will be created by the script: www_backup__DD.MM.YYYY_<random_string>.tar.gz (for example - www_backup_dbcp_21.10.2014_1RJKXbMv.tar.gz).

    The following files could exist inside the archive:

    1. DB dump /home/bitrix/mysql_dump__DD.MM.YYYY_.sql
    2. site kernel data
    3. sites Links-type data with full path

Managing backups via bx-sites

  • -a|--action - action to manage the site; in this case it executes backup
  • -d|--database - DB name (data for all sites that use this DB will be contained in the backup)
  • --enable|--disable - enabling and disabling backup for sites
  • --minute - parameters for crontab file record (minutes)
  • --hour - parameters for crontab file record (hours)
  • --day - parameters for crontab file record (day)
  • --month - parameters for crontab file record (month)
  • --weekday - parameters for crontab file record (week day)

In case of successful execution, the utility will return new options for site:

/opt/webdir/bin/bx-sites -a backup -d sitemanager0 --enable --minute=10 --hour=23 --day=1 --month=any --weekday=any -o json | python -mjson.tool  
            "BackupCronFile": "/etc/crontab",
            "BackupDay": "1",
            "BackupFolder": "/home/bitrix/backup/archive",
            "BackupHour": "23",
            "BackupMinute": "10",
            "BackupMonth": "*",
            "BackupTask": "enable",
            "BackupVersion": "v5",
            "BackupWeekDay": "*", 

Exclusion lists

Several files/catalogues are queried to be excluded from the backup copy. The list of such exclusions can be found in the file /opt/webdir/bin/ex.txt.

By default, it contains the following subcatalogues:


Backup contents/Restore from backup

As noted above, backup includes:

  • site kernel catalogue itself (kernel or ext_kernel);
  • DB dump file (/home/bitrix/mysql_dump_<db>.sql);
  • sites' catalogues (link), which use the kernel.

For example, the command:

/opt/webdir/bin/ sitemanager /home/bitrix/backup/archive 

creates file www_backup_sitemanager_30.01.2015_bnnW1NPm.tar.gz in the directory /home/bitrix/backup/archive/

To perform restoration from backup, unpack the backup archive to kernel's DocumentRoot. The example below uses a default site directory /home/bitrix/www:

tar -xvzf /home/bitrix/backup/archive/www_backup_sitemanager_09.03.2023_zJ34ogIj.tar.gz -C /home/bitrix/www/

After that, restore the database:

mysql sitemanager < /home/bitrix/www/home/bitrix/mysql_dump_sitemanager_09.03.2023_zJ34ogIj_after_connect.sql

You can use similar command to restore another file with site database backup:

mysql sitemanager < /home/bitrix/www/home/bitrix/mysql_dump_sitemanager_09.03.2023_zJ34ogIj.sql

Next restore data for the additional link type sites, if such are available:

rsync -av /home/bitrix/www/home/bitrix/ext_www/<site_name> /home/bitrix/ext_www/

Next, delete the database dump and additional site backups for security purposes.

rm -fr /home/bitrix/www/home/bitrix/*

Restoring data for another server

In case the copy is being restored on another server, first you have to create restored sites in the VMBitrix menu. At the same time, password for database in the archive won't match to the password from database at the new server, because passwords are generated at random after new virtual appliance is installed. It means that after restoring from backup, you need to change password for database user. This data can be taken from the section connections of the file /bitrix/.settings.php after unpacking the archive backup (bitrix0 - is the database user password for default site).

You can change the password via SQL query in mysql console:

SET PASSWORD FOR 'bitrix0'@'localhost' = PASSWORD('new_pass');

Next, restore the database dumps and backups for additional sites.

You need to perform similar actions, if /home/bitrix/ext_www directory was used as DocumentRoot for sites.

Attention!: Do not forget to monitor the space on disk and periodically delete old backup copies.

Courses developed by Bitrix24