PHPackages                             demi/backup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. demi/backup

ActiveYii2-extension[Debugging &amp; Profiling](/categories/debugging)

demi/backup
===========

Basic Yii2 site backup methods

1.1.1(4y ago)2020.8k↑33.3%5[4 issues](https://github.com/demisang/yii2-backup/issues)GPL-3.0-or-laterPHPPHP &gt;=5.4.0

Since Aug 10Pushed 4y ago4 watchersCompare

[ Source](https://github.com/demisang/yii2-backup)[ Packagist](https://packagist.org/packages/demi/backup)[ Docs](https://github.com/demisang/yii2-backup#readme)[ RSS](/packages/demi-backup/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Yii2-backup
===========

[](#yii2-backup)

Basic Yii2 site backup methods.
Also pay attention to [dropbox-backup](https://github.com/demisang/yii2-dropbox-backup).

Installation
------------

[](#installation)

Run

```
composer require "demi/backup" "~1.0"

```

Configurations
==============

[](#configurations)

### Minimal config

[](#minimal-config)

Configure **/common/config/main.php** or console config:

```
'components' => [
    'backup' => [
        'class' => 'demi\backup\Component',
        // The directory for storing backups files
        'backupsFolder' => dirname(dirname(__DIR__)) . '/backups', // /backups
        // Directories that will be added to backup
        'directories' => [
            'images' => '@frontend/web/images',
            'uploads' => '@backend/uploads',
        ],
    ],
]
```

#### Will create backup for:

[](#will-create-backup-for)

**directories:**
*/frontend/web/images/\**
*/backend/uploads/\**
**database:**
*Yii::$app-&gt;db*

#### Result:

[](#result)

**/backups/2015\_08\_11-05\_45\_48.tar/**
&gt;images.tar
&gt;uploads.tar
&gt;sql/blog.sql.gz

### Maximal config

[](#maximal-config)

```
[
'class' => 'demi\backup\Component',

// The directory for storing backups files
'backupsFolder' => dirname(dirname(__DIR__)) . '/backups', // /backups
// You can use alias:
'backupsFolder' => '@backend/backups', // /backend/backups

// Name template for backup files.
// if string - return date('Y_m_d-H_i_s')
'backupFilename' => 'Y_m_d-H_i_s',
// also can be callable:
'backupFilename' => function (\demi\backup\Component $component) {
    return date('Y_m_d-H_i_s');
},

// Directories that will be added to backup
'directories' => [
    // format:  =>
    'images' => '@frontend/web/images',
    'uploads' => '@backend/uploads',
],

// Name of Database component. By default Yii::$app->db.
// If you don't want backup project database
// you can set this param as NULL/FALSE.
'db' => 'db',
// Default DB host value
'defaultDbHost' => 'localhost',
// List of databases connections config.
// If you set $db param, then $databases automatically
// will be extended with params from Yii::$app->$db.
'databases' => [
    // It will generate "/sql/logs_table.sql.gz" with
    // dump file "logs_table.sql" of database 'logs'.
    // You can set custom 'mysqldump' command for each database,
    // just add 'command' param.
    'logs_table' => [
        'db' => 'logs', // database name. If not set, then will be used key 'logs_table'
        'host' => 'localhost', // connection host
        'username' => 'root', // database username
        'password' => 'BXw2DKyRbz', // user password
        'command' => 'mysqldump --add-drop-table --allow-keywords -q -c -u "{username}" -h "{host}" -p\'{password}\' {db} | gzip -9', // custom `mysqldump` command
    ],
],
// CLI command for creating each database backup.
// If $databases password is empty,
// then will be executed: str_replace('-p\'{password}\'', '', $command);
// it helpful when mysql password is not set.
// You can override this command with you custom params,
// just add them to $databases config.
'mysqldump' => 'mysqldump --add-drop-table --allow-keywords -q -c -u "{username}" -h "{host}" -p\'{password}\' {db} | gzip -9',

// Number of seconds after which the file is considered deprecated and will be deleted.
// To prevent deleting any files you can set this param as NULL/FALSE/0.
'expireTime' => 2592000, // 1 month
],
```

What's next
===========

[](#whats-next)

You can use this component anywhere.
For example, you can create console command
**/console/controllers/ToolsController.php:**

```
