Backing up files and databases
Script features:
- backup directories and databases
- uploading archives to a local folder or ftp
- informing by email about successful / unsuccessful completion
Creating backup directories is easy. Simply specify (path) to the folder that we want to archive and give a name to the backup (name). Optionally, you can specify the folders and files that we want to exclude (exclude).
The number of directories for which you need to create a backup can be several
It is equally easy to create a database backup. To do this, just specify the database name (db_name). Optionally, you can exclude some tables (for example, test ones) or import only the structure of tables (for example, the log table). As for directories, the number of databases can be several
Created bykap can be saved either to a local folder or upload via ftp. Here you can also specify the number of copies that you want to keep, that is, after loading a new archive, the old ones will be deleted
After the backup is created and saved in the specified location, you can set up an email alert. Upon successful completion (on_success), a letter template will be taken that you specify (template), all statistics will be parsed into it and sent to the email address you specified. You can also configure sending letters when any errors occur (on_failed)
Config example:
Usage example:
Crohn example:
Sources here
- backup directories and databases
- uploading archives to a local folder or ftp
- informing by email about successful / unsuccessful completion
Backup directories
Creating backup directories is easy. Simply specify (path) to the folder that we want to archive and give a name to the backup (name). Optionally, you can specify the folders and files that we want to exclude (exclude).
The number of directories for which you need to create a backup can be several
Backup db
It is equally easy to create a database backup. To do this, just specify the database name (db_name). Optionally, you can exclude some tables (for example, test ones) or import only the structure of tables (for example, the log table). As for directories, the number of databases can be several
Download backup
Created bykap can be saved either to a local folder or upload via ftp. Here you can also specify the number of copies that you want to keep, that is, after loading a new archive, the old ones will be deleted
Backup Completion Notifications
After the backup is created and saved in the specified location, you can set up an email alert. Upon successful completion (on_success), a letter template will be taken that you specify (template), all statistics will be parsed into it and sent to the email address you specified. You can also configure sending letters when any errors occur (on_failed)
Using
Config example:
array(
// common options'common' => array(
'tar_cmd' => '/bin/tar',
'gzip_cmd' => '/bin/gzip',
'backup_filename_prefix' => $prefix,
'backup_filename' => 'backupname',
),
// backup options'backup' => array(
// directory backup'directory' => array(
'tar_cmd' => '/bin/tar',
'items' => array(
array(
'name' => 'home_user1',
'path' => '/home/user1',
'exclude' => 'tmp,logs,cache',
),
array(
'name' => 'home_user2',
'path' => '/home/user2',
'exclude' => 'tmp',
)
)
),
// database backup'mysql' => array(
'mysqldump_cmd' => '/usr/bin/mysqldump',
'user' => 'root',
'password' => 'xxx',
'host' => 'localhost',
'items' => array(
array(
'db_name' => 'xxx',
'ignore_tables' => 'test',
'tables_structure' => 'logs,sessions',
),
array(
'db_name' => 'xxx2',
),
),
),
),
// upload backup options'upload' => array(
// upload to local directoey'directory' => array(
'max_count' => 3,
'path' => '/backups',
),
// upload to ftp'ftp' => array(
'max_count' => 3,
'path' => '/backups',
'host' => 'xxx',
'user' => 'xxx',
'password' => 'xxx'
),
),
// notification options'nofification' => array(
// email notification'email' => array(
'on_success' => array(
'to' => 'xxx@xxx.xxx',
'subject' => 'Success backup',
'template' => realpath(__DIR__ . '/../Command/Notification/email_templates/success.php')
),
'on_failed' => array(
'to' => 'xxx@xxx.xxx',
'subject' => 'Failed backup',
'template' => realpath(__DIR__ . '/../Command/Notification/email_templates/failed.php')
),
),
),
Usage example:
$backupTask = new BackupTask\BackupTask($config);
$backupTask->run();
Crohn example:
@daily /usr/bin/php /path/to/backup.php daily
@weekly /usr/bin/php /path/to/backup.php weekly
@monthly /usr/bin/php /path/to/backup.php monthly
Sources here