h1. Backup and recovery h2. Manual database backup The system stores the data in a database, hereinafter referred to as _DB_ and in files. _DB_ consists of 3 databases: * _config_ contains configuration data * _storage_ contains CDR and other bulk data * _var_ contains local temporary data, such as a table of active calls The most valuable data is contained in the _config_ and _storage_ databases. h3. config The _config_ database is stored in the _InnoDB_ format. The system by default creates a backup of the _config_ database in the form of an SQL dump every 6 hours. Backups are saved in archives /var/backup/smartswitch. You have backups for every 6 hours for the last month at any given time. You may want to use backup in the following cases: * irreparable corruption of _InnoDB_ log files due to incorrect system reboot * operator error (for example deleting important information) To restore the _config_ database from backup, use the following instructions (assuming that you want to restore the 010600.tgz archive: *Attention! If you are a Streamco customer, do not perform the following operations yourself! You can ruin all your data. Contact technical support!*
# sudo -s
# cd /usr/local/smartswith/mysql
# tar zxvf /var/backups/smartswitch/010600.tgz
# mysql
mysql> drop database config;
mysql> create database config;
mysql> exit
# mysql config < 010600/config.sql
You can configure _rsync_ to backup these files to your server. Install the _expect_ package and add the following script to run periodically on the remote host:
#!/bin/sh

SSH_LOGIN=
SSH_PASSWORD=
HOST_IP=
expect -c "spawn rsync -axSRzv $SSH_LOGIN@$HOST_IP:/var/backups/smartswitch ./; expect \"*?assword:*\" {send \"$SSH_PASSWORD\r\"; interact};"
h3. storage The _storage_ database is stored in the _MyISAM_ format. The _storage_ database is not backed up to a local disk due to its large size. _MyISAM_ is not logged, therefore, in case of incorrect reboots, the entire database can be restored without resorting to backups. In case of damage, the standard procedure for restoring MyISAM MySQL databases is used (for example, to restore the cdr table): *Attention! If you are a Streamco customer, do not perform the following operations yourself! You can ruin all your data. Contact technical support!*
mysql> repair table cdr use_frm;
With this command you will restore the cdr table. Similarly, you can recover any other damaged table. The system has a script that automatically restores all tables:
/usr/local/bin/smartswitch/repair.sh
Run it to restore the storage database after an incorrect power reboot of the server. You can also set up replication of this database to another server to maintain a constantly up-to-date backup copy. In this case, even if the main server completely fails, you are guaranteed to have a snapshot of the database on the server to which you are replicating. For more information about this feature, see [[MySQL_Replication]]. h3. var This database does not store important data. However, it does have the necessary tables and stores the license key. It is enough to back it up just once (however, you need to make a backup after each update, since the database format usually changes with an update):
# mysqldmp --single-transaction -S /usr/local/smartswitch/mysql_var/mysql.sock var > var.sql
Copy the resulting var.sql somewhere and use the procedure to restore: *Attention! If you are a Streamco customer, do not perform the following operations yourself! You can cause the entire system to crash. Contact technical support!*
# mysql -S /usr/local/smartswitch/mysql_var/mysql.sock var
mysql> drop database var;
mysql> create database var;
mysql> exit
# mysql -S /usr/local/smartswitch/mysql_var/mysql.sock var < var.sql
h2. Backup and recovery of files Important files are recordings of telephone conversations. They are stored in /usr/local/smartswitch/recordings. You can configure _rsync_ to backup these files to your server. Install the _expect_ package and add the following script to run periodically on the remote host:
#!/bin/sh

SSH_LOGIN=
SSH_PASSWORD=
HOST_IP=
expect -c "spawn rsync -axSRzv $SSH_LOGIN@$HOST_IP:/usr/local/smartswitch/recordings ./; expect \"*?assword:*\" {send \"$SSH_PASSWORD\r\"; interact};"
h2. Manual file system backup To backup the file system, use the following procedure:
# mkdir backup
# cd backup
# dump -0 -L -f - / | gzip -9 > root.img.gz
# dump -0 -L -f - /usr | gzip -9 > usr.img.gz
# dump -0 -L -f - /var | gzip -9 > var.img.gz
Transfer the files to your PC. Let your login be _admin_, and the server IP address be _192.168.0.1_.
# pscp.exe -r admin@192.168.0.1:backup backup
After this, you have snapshots of all file systems on your PC. To restore from a backup, first install the system from our installation disk, and then transfer the backup to it:
# pscp.exe -r backup admin@192.168.0.1:
Then restore from backup:
# cd backup
# gzip -d root.img.gz | ( cd / ; restore -rf - )
# gzip -d usr.img.gz | ( cd /usr ; restore -rf - )
# gzip -d var.img.gz | ( cd /var ; restore -rf - )
h2. Automatic full system backup For loaded production systems, the manual backup method is not suitable, since data loss is possible in the interval between the backup and the hardware failure. To set up automatic backup, our company’s engineers use “MySQL replication”: http://dev.mysql.com/doc/refman/5.0/en/replication.html. together with the use of _rsync_. Setting up _replication_ is beyond the scope of this guide. [[Бекап и восстановление|Русский перевод]]