PDA

View Full Version : SM3: Do I really need to schedule hot db backups in cron?



lychina
30-Mar-2017, 16:56
According to the Best Practices document (14.4), the first hot backup can be performed by:

# mkdir /var/spacewalk/db-backup
# chown postgres:postgres /var/spacewalk/db-backup
# chmod 700 /var/spacewalk/db-backup
# smdba backup-hot --enable=on --backup-dir=/var/spacewalk/db-backup
and successive hot backups can be performed by:

# smdba backup-hot --backup-dir=/var/spacewalk/db-backup

To automate this with cron, according to 14.5, after the above, add the following entry to /etc/cron.d/db-backup-mgr:
0 2 * * * root /usr/bin/smdba backup-hot --enable=on --backup-dir=/var/spacewalk/db-backup

A few questions:
1. I performed the first hot backup and did *not* create /etc/cron.d/db-backup-mgr for successive backups yet my /var/spacewalk/db-backup directory is populatred every few hours with backups:

# cd /var/spacewalk/db-backup
# ls -l
-rw------- 1 postgres postgres 16777216 Mar 28 10:56 000000010000000400000070
-rw------- 1 postgres postgres 16777216 Mar 28 11:03 000000010000000400000071
-rw------- 1 postgres postgres 305 Mar 28 11:03 000000010000000400000071.00000028.backup
-rw-r--r-- 1 postgres postgres 1549039115 Mar 28 11:03 base.tar.gz
drwx------ 2 postgres postgres 6 Mar 28 11:03 tmp
-rw------- 1 postgres postgres 16777216 Mar 28 12:30 000000010000000400000072
-rw------- 1 postgres postgres 16777216 Mar 28 13:22 000000010000000400000073
-rw------- 1 postgres postgres 16777216 Mar 28 14:37 000000010000000400000074
-rw------- 1 postgres postgres 16777216 Mar 28 17:00 000000010000000400000075
-rw------- 1 postgres postgres 16777216 Mar 28 19:22 000000010000000400000076
-rw------- 1 postgres postgres 16777216 Mar 28 21:47 000000010000000400000077
-rw------- 1 postgres postgres 16777216 Mar 29 00:08 000000010000000400000078
-rw------- 1 postgres postgres 16777216 Mar 29 02:33 000000010000000400000079
-rw------- 1 postgres postgres 16777216 Mar 29 03:11 00000001000000040000007A
-rw------- 1 postgres postgres 16777216 Mar 29 03:14 00000001000000040000007B
-rw------- 1 postgres postgres 16777216 Mar 29 05:30 00000001000000040000007C
-rw------- 1 postgres postgres 16777216 Mar 29 07:57 00000001000000040000007D
-rw------- 1 postgres postgres 16777216 Mar 29 10:18 00000001000000040000007E
-rw------- 1 postgres postgres 16777216 Mar 29 12:43 00000001000000040000007F
...
-rw------- 1 postgres postgres 16777216 Mar 30 03:38 00000001000000040000009A
-rw------- 1 postgres postgres 16777216 Mar 30 03:38 00000001000000040000009B
-rw------- 1 postgres postgres 16777216 Mar 30 03:38 00000001000000040000009C
-rw------- 1 postgres postgres 16777216 Mar 30 03:39 00000001000000040000009D
-rw------- 1 postgres postgres 16777216 Mar 30 03:39 00000001000000040000009E
-rw------- 1 postgres postgres 16777216 Mar 30 03:39 00000001000000040000009F
-rw------- 1 postgres postgres 16777216 Mar 30 03:40 0000000100000004000000A0
-rw------- 1 postgres postgres 16777216 Mar 30 03:43 0000000100000004000000A1
-rw------- 1 postgres postgres 16777216 Mar 30 05:09 0000000100000004000000A2
-rw------- 1 postgres postgres 16777216 Mar 30 07:30 0000000100000004000000A3
-rw------- 1 postgres postgres 16777216 Mar 30 09:32 0000000100000004000000A4
-rw------- 1 postgres postgres 16777216 Mar 30 10:27 0000000100000004000000A5
Is this because --enable-hot "activated" some automated hot backup mechanism which does the same action as the cron entry suggested in 14.5? Or are these WAL files belonging to the backup that will be purged the next time "smdba backup-hot" is run?
2. Depending on the answer to question #1, do I need to add the crontab entry? And, if I do, do I really need --enable=on again?
3. Do I need to worry about manually removing old files from the database backup directory, /var/spacewalk/db-backup?
4. Should I run pg_archivecleanup to purge old archivelogs from /var/lib/pgsql/data/pg_xlog?

lychina
30-Mar-2017, 17:41
Answering my own questions after further research:
1. Yes, these are WAL files that will be cleaned up by smdba backup-hot.
2. Yes, a crontab entry is needed. Will use --enable=on.
3. No need to manually remove the WAL files under /var/spacewalk/db-backup as smdba backup-hot does this automatically.
4. Yes, pg_archivecleanup needs to be run manually to purge old WAL files from /var/lib/pgsql/data/pg_log.

I am working on a script to do all of the above. Will post when complete.