[KUBE](../README.md)  /  Backup # Backup - [Creation](#creation) - [Verification](#verification) - [Cleanup](#cleanup) - [LongTerm](#longterm) - [Commands](#commands) *** ## Creation Directory structure of backups on the host machine: `//`. - `` – set by the `backupPath` parameter. - `` – backup creation date in the format `YYYY-MM-DD`. - `` – a marker indicating the backup creation time in the format `HH-MM-SS`, with the first backup of the day named ``. When the backup process starts, a directory `//` is created (if it does not exist), where the backup files will be stored. First, a backup of files is created depending on the `backupType` parameter: - `archive` – all subdirectories from `vhostsPath` are packed individually into separate archives named `.tar.gz`. - `rsync` – backup of the `vhostsPath` directory contents using the `rSync` utility. Then, in each subdirectory of `vhostsPath`, the file `www/wp-config.php` is searched for, and database connection parameters are read from it. After that, the database is exported to a file and packed into an archive named `.sql.tar.gz`. Next, the backup is copied to an external storage using the `rSync` utility. Two types of external storage (`storageType`) are supported: - `rsync` – for full functionality, connection parameters `rRync` and `FTP` must be set. - `ssh` – for full functionality, connection parameters `SSH` must be set. Backup directory structure on external storage: `/`. Set by the following parameters: - `storagePath` – general path parameter for external storage - `rsyncPath` – path parameter for `rSync` - `ftpPath` – path parameter for `FTP` - `sshPath` – path parameter for `SSH` Example: ```bash storagePath="/$hostname" rsyncPath="$storagePath" ftpPath="$storagePath" sshPath="/_storage$storagePath" ``` Inside `/`, the directory structure on external storage fully mirrors the structure of `` on the host machine. *** ## Verification There are two types of backup verification available: verifying the latest backup and verifying all backups created on the current day. When verifying the latest backup, the system searches for the latest backup execution log (directory `logs/backup` in the script folder). The file name is used to check the elapsed time since the last backup creation (parameter `backupElapsedMax`). The log contains the backup creation directory. Then, a non-recursive scan of subdirectories and files in the backup directory `//` is performed. All directories and `*.tar.gz` files are considered website file backups, while `*.sql.tar.gz` files are considered database backups. A comparison is made between website file backups and database backups, and any discrepancies are noted. Next, the archive file sizes are checked (the minimum allowable size is set by the parameter `backupFileSizeMin`). The next step is verifying the backup on external storage. The presence of the same subdirectories and files (non-recursively) is checked: ```bash ///* --> ////* ``` A non-recursive file size comparison is performed, and any discrepancies are noted. When verifying backups created on the current day, the day's directories are first compared: ```bash //* --> ///* ``` Then, each subdirectory is compared as described above. *** ## Cleanup Backups cleanup occurs once every 24 hours. It is configured using two parameters: - `backupDays` – the number of past days (excluding the current day) for storing backups on the host machine. - `storageDays` – the number of past days (excluding the current day) for storing backups on external storage. Example: ```bash /2025-05-20/ /2025-05-10/ /2025-05-05/ /2025-05-01/ ``` When `backupDays=2` and run `2025-05-20` will remain: ```bash /2025-05-20/ /2025-05-10/ /2025-05-05/ ``` If `backupDays=2` and run after `2025-05-20` will remain: ```bash /2025-05-20/ /2025-05-10/ ``` *** ## LongTerm The `backupLongTermDays` parameter is responsible for the number of days for a long-term backup. When the corresponding command, the following happens 1. The contents of the long-term backups directory (`/_longterm`) are checked. 2. All copies older than `backupLongTermDays` except the earliest one are deleted. 3. If there are no backups younger than `backupLongTermDays`, the first backup for the last day available is moved: ```bash // --> /_longterm// ``` *** ## Commands ### `-b, --backup [option]` Backup files and database of one site or all sites. Options: - `archive` - backup all domains to archives - `rsync` - backup all domains using rSync - `` - backup domain to archives (e.g., `example.com`) > [!NOTE] > The default value (`archive` or `rsync`) is set by the `backupType` variable in the configuration file `config.sh`. Example: ```bash sudo kube.sh -b sudo kube.sh -b archive sudo kube.sh -b example.com ``` Directory structure of backups: `//` - `` - Date format `YYYY-MM-DD` (e.g., `2025-05-20`) - `` - First backup for day: `` (`_first`), all next in time format `HH-MM-SS` (e.g., `09-30-55`) Backup options: - `archive` - creates 2 archives and copies the `.conf` file for all sites + copies file `map.conf`: - `///.tar.gz` - `///.sql.tar.gz` - `///.conf` - `///map.conf` - `rsync` - copies the `vhostsPath` virtual hosts folders, creates database archives and copied and database archives are created and copies `.conf` file for all sites + copies file `map.conf`: - `///` - `///.sql.tar.gz` - `///.conf` - `///map.conf` - `domain` - creates 2 archives and copies the `.conf` file for the site: - `///.tar.gz` - `///.sql.tar.gz` - `///.conf` Example: ```bash /backup/2025-05-21/08-00-00/example.com /backup/2025-05-21/08-00-00/example.com.conf /backup/2025-05-21/08-00-00/example.com.sql.tar.gz /backup/2025-05-21/_first/example.com /backup/2025-05-21/_first/example.com.conf /backup/2025-05-21/_first/example.com.sql.tar.gz /backup/2025-05-21/_first/map.conf /backup/2025-05-21/12-12-12/example.com.conf /backup/2025-05-20/12-12-12/example.com.tar.gz /backup/2025-05-20/12-12-12/example.com.sql.tar.gz ```