Files
2026-08-18 09:40:08 +02:00

6.8 KiB
Raw Permalink Blame History

KUBE  /  Backup

Backup


Creation

Directory structure of backups on the host machine: <backup path>/<date>/<marker>.

  • <backup path> – set by the backupPath parameter.
  • <date> – backup creation date in the format YYYY-MM-DD.
  • <marker> – a marker indicating the backup creation time in the format HH-MM-SS, with the first backup of the day named <backupFirst>. When the backup process starts, a directory <backup path>/<date>/<marker> 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 <directory>.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 <directory>.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: <storage path>/<hostname>. 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:

storagePath="/$hostname"
rsyncPath="$storagePath"
ftpPath="$storagePath"
sshPath="/_storage$storagePath"

Inside <storage path>/<hostname>, the directory structure on external storage fully mirrors the structure of <backup path> 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 <backup path>/<date>/<marker> 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:

<backup path>/<date>/<marker>/*  -->  <storage path>/<hostname>/<date>/<marker>/*

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:

<backup path>/<date>/*  -->  <storage path>/<hostname>/<date>/*

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:

<backupPath>/2025-05-20/
<backupPath>/2025-05-10/
<backupPath>/2025-05-05/
<backupPath>/2025-05-01/

When backupDays=2 and run 2025-05-20 will remain:

<backupPath>/2025-05-20/
<backupPath>/2025-05-10/
<backupPath>/2025-05-05/

If backupDays=2 and run after 2025-05-20 will remain:

<backupPath>/2025-05-20/
<backupPath>/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 (<backupPath>/_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:
<backupPath>/<last day>/<backupFirst> --> <backupPath>/_longterm/<last day>/<backupFirst>

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
  • <domain> - 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:

sudo kube.sh -b
sudo kube.sh -b archive
sudo kube.sh -b example.com

Directory structure of backups: <backupPath>/<date>/<marker>

  • <date> - Date format YYYY-MM-DD (e.g., 2025-05-20)
  • <marker> - First backup for day: <backupFirst> (_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:
    • <backupPath>/<date>/<marker>/<domain*>.tar.gz
    • <backupPath>/<date>/<marker>/<domain*>.sql.tar.gz
    • <backupPath>/<date>/<marker>/<domain*>.conf
    • <backupPath>/<date>/<marker>/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:
    • <backupPath>/<date>/<marker>/<domain*>
    • <backupPath>/<date>/<marker>/<domain*>.sql.tar.gz
    • <backupPath>/<date>/<marker>/<domain*>.conf
    • <backupPath>/<date>/<marker>/map.conf
  • domain - creates 2 archives and copies the .conf file for the site:
    • <backupPath>/<date>/<marker>/<domain>.tar.gz
    • <backupPath>/<date>/<marker>/<domain>.sql.tar.gz
    • <backupPath>/<date>/<marker>/<domain>.conf

Example:

/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