It is possible (and strongly recommended) to perform periodical backups of CARTO Builder On-Premises. This will allow you to recover both data, and configurations, in case of disaster.
backup.rb - It offers two methods for creating a backup: rsync and
tar. Backups take everything under the directory provided by
--data-dir
and stores it in --backup-dir
directory. The script has
the ability to check if this is a mount point backup; which are done to
an external drive, e.g network drive.
Depending on the backup method chosen, the following scenarios may apply:
If rsync is chosen, the backup directory provided by the --backup-dir
flag (e.g --backup-dir /backup/production
) that will be updated every
time that the script is run. :
1
2
3
4
5
6
7
8
9
10
/opt/carto/tools/bin/cartoctl exec -- backup.rb --help
Usage: backup [options]
-c, --check-mount Check if backup dir is a mount point
-r, --redis-retries=val Retries to check Redis backup completed
-m, --method=val Backup method: rsync (default) or tar
-d, --data-dir=val Data dir to backup
-b, --backup-dir=val Output dir to write backup to
-h Shows this message
/opt/carto/tools/bin/cartoctl exec -- backup.rb --data-dir /data --backup-dir /backup
The script requires both --data-dir
and backup-dir
to be provided in
order to run.
If tar is chosen, there should be a separate tar file every time the backup script is run.
By default, backups are not performed automatically. The user is responsible for running the backup task periodically in cron, or any other method.
The following usage example describes how a backup script is applied:
1
2
3
4
5
$ /opt/carto/tools/bin/cartoctl exec -- backup.rb --data-dir /data --backup-dir /backup --method tar
$ ll /backup/
total 4316
-rw-r--r-- 1 root root 4417656 Sep 30 15:17 carto_backup_20190930151723.tar.gz
The script requires both --data-dir
and backup-dir
to be provided in
order to run.
restore-backup.rb stops all services, takes a backup as generated by
backup.rb tool, pointed to by the --rsync-dir
or --tar-file
,
depending on which method has been used to make the backup, restores it
into the directory provided by the --data-dir
flag, and starts all
services. By default, it tries to keep whatever --data-dir
had unless
told otherwise. Two different inputs can be provided:
The following usage example describes how a backup restore script is applied:
1
2
3
4
5
6
7
/opt/carto/tools/bin/cartoctl exec -- restore-backup.rb --help
Usage: restore-backup [options]
-d, --rsync-dir=val Rsync'ed dir to restore
-f, --tar-file=val Tar file to restore
-o, --output-dir=val Output data dir to restore backup to
-r, --remove-data-dir Removes data dir. We keep it by default
-h Shows this message
It is required to pass either option -d or option -f, and the output directory (-o, –output-dir) to restore to.
The following example comes from the restore of a Builder installation, from a directory backup created with backup script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ /opt/carto/tools/bin/cartoctl exec -- restore-backup.rb -d /backup/data/ -o /data
This script is going to restore /backup/data/
into /data local data dir. If the provided data dir exists, it will try
to keep it unless you have asked explicitly to not do it.
Please make sure backup comes from carto-backup.rb script in an unaltered form
or things won't work as expected
Do you want to proceed? (y/N)y
2019-09-30 14:58:04 UTC - INFO - ./tools/common-templates/restore-backup.rb starts
2019-09-30 14:58:04 UTC - INFO - Stopping all services
2019-09-30 14:58:04 UTC - DEBUG - Service postgresql stop
2019-09-30 14:58:04 UTC - DEBUG - Service redis stop
2019-09-30 14:58:04 UTC - INFO - Saving /data into /data.save
2019-09-30 14:58:04 UTC - DEBUG - Running command [mv /data /data.save]
2019-09-30 14:58:04 UTC - INFO - Recovering backup from /backup/data/
2019-09-30 14:58:04 UTC - DEBUG - Running command [rsync -a /backup/data /]
2019-09-30 14:58:05 UTC - DEBUG - Running command [mv /data/log/redis /data/log/redis.save]
2019-09-30 14:58:05 UTC - DEBUG - Running command [mkdir -p /data/log/redis]
2019-09-30 14:58:05 UTC - DEBUG - Running command [touch /data/log/redis/redis.log]
2019-09-30 14:58:05 UTC - DEBUG - Running command [chown redis: /data/log/redis/redis.log]
2019-09-30 14:58:05 UTC - INFO - Starting all services
2019-09-30 14:58:05 UTC - DEBUG - Service redis start
2019-09-30 14:58:05 UTC - DEBUG - Service postgresql start
2019-09-30 14:58:12 UTC - INFO - Remove /data.save if things are ok
2019-09-30 14:58:12 UTC - INFO - ./tools/common-templates/restore-backup.rb ends
In order to restore a server using a backup, the cleanest approach would be to install the product using the installer for the version. Then use the restore script from the latest backup.