The final executors of all operations are
pg_dump
andpsql
. If you created a backup on one server and are restoring it on another, make sure you are upgrading the PostgreSQL version with the commandpsql -V
. Downgrading the version will likely result in the backup not being deployed.
Navigate to the totum folder:
cd /home/totum/totum-mit
Execute:
bin/totum schema-backup --schema="SCHEMA_NAME" prod_dump.sql
SCHEMA_NAME
= default is totum
bin/totum schema-backup --schema="SCHEMA_NAME" --no-logs --gz file_dump.sql
bin/totum schema-backup --schema="SCHEMA_NAME" --no-content="table_name_1,table_name_2" file_dump.sql
Create a dump. Execute from the root folder of Totum. Replace USER
and PASSWORD
with those corresponding to your database.
SCHEMA_NAME
— the name of the schema. You can view it in any table in Totum in the upper right corner.
pg_dump -O -x --dbname=postgresql://USER:PASSWORD@LOCALHOST:5432/DB_NAME --schema="SCHEMA_NAME" > db_backup_name.sql
-O
— means without owner, so this dump can be restored on another host.
-x
— without privileges.
db_backup_name.sql
— you can create a backups
folder in the root folder of Totum and specify the full or relative path to it along with the name of the backup file.
bin/totum schema-backup
executes thepg_dump
command excluding external synchronization logs and temporary tables!
If you need to export without logs:
pg_dump -O -x --dbname=postgresql://USER:PASSWORD@LOCALHOST:5432/DB_NAME --schema="SCHEMA_NAME" --no-tablespaces --exclude-table-data='_tmp_tables' --exclude-table-data='_bfl' | grep -v '^--' > db_backup_name.sql
You can schedule the creation of a dump in cron
within Totum using the execSSH function.
Example of Totum code creating copies in the root folder of Totum:
PATH_TO_TOTUM_FOLDER
— replace with the path to the Totum folder. You can view it by executing pwd
in the server console.
The second action deletes a 7-day-old file. Schedule it in cron to execute once a day.
Replace SCHEMA_NAME
with the schema name (default is totum
):
= : while(action: $a1; action: $a2)
a1: execSSH(ssh: "cd ~/totum-mit && bin/totum schema-backup --schema='SCHEMA_NAME' --gz '%schema%-%Y%-%m%-%d%.sql'")
a2: execSSH(ssh: str`"cd ~/totum-mit && rm SCHEMA_NAME-" + $dm + ".sql.gz"`)
dm: dateAdd(date: $#nd; days: -7; format: "Y-m-d")
If Totum issues a warning about blocking execSSH during execution — remove the comment from the line /* protected $execSSHOn = true;*/
in Conf.php in the root installation folder, it should be -> protected $execSSHOn = true;
execSSH
is available only in the PRO version
Replace HOST
with your Host:
Files are located at /home/totum/totum-mit/http/fls/HOST
and /home/totum/totum-mit/totumTmpfiles/HOST
.
For protected files, /home/totum/totum-mit/secureFiles/HOST
.
You need to back up these folders by any means.
When performing this operation from the root folder of Totum, the database schema is completely replaced with the schema from prod_dump.sql
(replace schema_name
with your schema):
bin/totum schema-replace --with-active-crons file_dump.sql schema_name
bin/totum schema-replace --with-active-crons file_dump.sql schema_name host.zone
By default, crons are disabled during loading — --with-active-crons
disables this rule
To restore, enter psql and the folder where the backup file is located. Replace USER
and PASSWORD
with those corresponding to your database.
psql --dbname=postgresql://user:password@localhost:5432/db_name
Rename the current schema to reserve:
ALTER SCHEMA schema_name RENAME TO reserve_name;
# enter, semicolon at the end of the line is mandatory
Load the restoration:
\i backup_file_name
# enter without a semicolon
Check the restoration, and if okay, delete the renamed old schema
DROP SCHEMA reserve_name CASCADE;
# enter, semicolon at the end of the line is mandatory
How to view the list of all schemas in the database:
select schema_name from information_schema.schemata;
# enter, semicolon at the end of the line is mandatory
Exit
\q
# enter