{"id":30,"date":"2012-11-06T01:27:37","date_gmt":"2012-11-06T09:27:37","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=30"},"modified":"2012-11-06T01:27:37","modified_gmt":"2012-11-06T09:27:37","slug":"recover-bacula-catalog-database-after-accidental-purge-of-jobs","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/recover-bacula-catalog-database-after-accidental-purge-of-jobs\/","title":{"rendered":"Recover Bacula Catalog Database After Accidental Purge of Jobs"},"content":{"rendered":"
I accidentally purged jobs from the Bacula catalog.\u00a0 I recovered by using the ASCII sql export from the previous day. I am using sqlite for the DB but mysql should work similar. Read through \/etc\/bacula\/scripts\/make_catalog_backup near the end for some breadcrumbs around database recovery.<\/p>\n
I had the following jobs in the catalog before I screwed up.<\/p>\n
root@bcla001:~# echo \"list jobs\" | bconsole | grep -i dracula\r\n| 10 | job_dracula | 2012-09-09 11:57:11 | B | F | 288319 | 2234447730266 | T |\r\n| 13 | job_dracula | 2012-09-14 23:58:05 | B | F | 288563 | 2260608426041 | T |\r\n| 45 | job_dracula | 2012-10-14 00:56:53 | B | F | 0 | 0 | f |\r\n| 46 | job_dracula | 2012-10-14 01:07:35 | B | F | 0 | 0 | R |<\/pre>\nFor some reason I thought I will cleanup a bunch of failed jobs in the catalog using purge<\/strong>. Hindsight is 20 \/ 20 as they say....<\/p>\n
*purge \r\n\r\nThis command can be DANGEROUS!!!\r\n\r\nIt purges (deletes) all Files from a Job,\r\nJobId, Client or Volume; or it purges (deletes)\r\nall Jobs from a Client or Volume without regard\r\nto retention periods. Normally you should use the\r\nPRUNE command, which respects retention periods.\r\nYou have the following choices:\r\n 1: files\r\n 2: jobs\r\n 3: volume\r\nChoose item to purge (1-3): 2\r\nThe defined Client resources are:\r\n 1: bcla001-fd\r\n 2: server002-fd\r\n 3: dracula-fd\r\nSelect Client (File daemon) resource (1-3): 3\r\nBegin purging jobs from Client \"dracula-fd\"\r\nNo Files found for client dracula-fd to purge from MyCatalog catalog.<\/pre>\nRebuild the DB as follow. Stopping bacula services first.<\/strong><\/p>\n
root@bcla001:\/var\/lib# \/etc\/init.d\/bacula-director stop\r\n[ ok ] Stopping Bacula Director...: bacula-dir.\r\nroot@bcla001:\/var\/lib# \/etc\/init.d\/bacula-fd stop\r\n[ ok ] Stopping Bacula File daemon...: bacula-fd.\r\nroot@bcla001:\/var\/lib# \/etc\/init.d\/bacula-sd stop\r\n[ ok ] Stopping Bacula Storage daemon...: bacula-sd.\r\n\r\nroot@bcla001:\/var\/lib# ps -ef | grep bacula\r\n\r\nroot@bcla001:\/var\/lib\/bacula# mv bacula.db bacula.db.101312\r\n\r\nroot@bcla001:\/var\/lib\/bacula# sqlite3 bacula.db < bacula.sql\r\n\r\nroot@bcla001:\/var\/lib\/bacula# chown bacula.bacula bacula.db\r\n\r\nroot@bcla001:\/var\/lib\/bacula# ls -lh bacula.db\r\n-rw-r--r-- 1 bacula bacula 1.1G Oct 14 00:43 bacula.db\r\n\r\nroot@bcla001:\/var\/lib\/bacula# \/etc\/init.d\/bacula-sd start\r\n[ ok ] Starting Bacula Storage daemon...: bacula-sd.\r\nroot@bcla001:\/var\/lib\/bacula# \/etc\/init.d\/bacula-fd start\r\n[ ok ] Starting Bacula File daemon...: bacula-fd.\r\nroot@bcla001:\/var\/lib\/bacula# \/etc\/init.d\/bacula-director start\r\n[ ok ] Starting Bacula Director...: bacula-dir.\r\n\r\nroot@bcla001:\/var\/lib\/bacula# ps -ef | grep bacula\r\nbacula 8961 1 0 00:46 ? 00:00:00 \/usr\/sbin\/bacula-sd -c \/etc\/bacula\/bacula-sd.conf -u bacula -g tape\r\nroot 9006 1 0 00:46 ? 00:00:00 \/usr\/sbin\/bacula-fd -c \/etc\/bacula\/bacula-fd.conf\r\nbacula 9036 1 0 00:46 ? 00:00:00 \/usr\/sbin\/bacula-dir -c \/etc\/bacula\/bacula-dir.conf -u bacula -g bacula<\/pre>\n","protected":false},"excerpt":{"rendered":"I accidentally purged jobs from the Bacula catalog.\u00a0 I recovered by using the ASCII sql export from the previous day.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-backups"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}