{"id":396,"date":"2017-05-12T08:57:21","date_gmt":"2017-05-12T08:57:21","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=396"},"modified":"2020-05-25T12:55:02","modified_gmt":"2020-05-25T12:55:02","slug":"bacula-backup-systems-server","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=396","title":{"rendered":"Bacula Backup Systems (Server)"},"content":{"rendered":"<p>Bacula is a very powerful enterprise level backup solution which can backup localhost, and even remote host via network. It has these components<\/p>\n<ul>\n<li>Director<\/li>\n<li>Storage server<\/li>\n<li>Cateloge &#8211; Database server<\/li>\n<li>Console Server<\/li>\n<\/ul>\n<p>The installation process is pretty straight forward in Redhat Linux or CentOS. The OS that I used in my lab is CentOS 7. I am sure it will be similar on others\u00a0Redhat and CentOS systems too<\/p>\n<p>Let us begin by installing all required packages in an updated CentOS system<\/p>\n<p><strong>#] <em>yum install -y bacula-director bacula-storage bacula-console bacula-client mariadb-server<\/em><\/strong><\/p>\n<p>Let us start the DB server<br \/>\n<strong>#] <em>systemctl start mariadb<\/em><\/strong><\/p>\n<p>Let us granted user bacula Privileges on database by running a scrip that got installed when other packages were installed<br \/>\n<strong>#] <em>\/usr\/libexec\/bacula\/grant_mysql_privileges<\/em><\/strong><\/p>\n<p>Let us create bacula databases using the pre-istalled script<br \/>\n<strong>#] <em>\/usr\/libexec\/bacula\/create_mysql_database -u root<\/em><\/strong><\/p>\n<p>Let us create the tables used by bacula\u00a0using the pre-installed script<br \/>\n<strong>#] <em>\/usr\/libexec\/bacula\/make_mysql_tables -u bacula<\/em><\/strong><\/p>\n<p>Secure the Database server by assigning a Root Password and leaving the remaining option with default value<\/p>\n<p><strong>#]<\/strong>mysql_secure_installation<\/p>\n<p>Let us assign a password for the root user in MariaDB server. Login to the server as root and run the following command:<br \/>\n<strong>DB&gt; <em>UPDATE mysql.user SET Password=PASSWORD(&#8216;my_bacula_pw&#8217;) WHERE User=&#8217;bacula&#8217;;<\/em><\/strong><\/p>\n<p>Let us flush the user privileges in the DB server<br \/>\n<strong>DB&gt; <em>FLUSH PRIVILEGES;<\/em><\/strong><\/p>\n<p>Exit from MySQL console<\/p>\n<p>Let us\u00a0ensure the database server starts during the startup of the host<\/p>\n<p><strong>#] <em>systemctl enable mariadb<\/em><\/strong><\/p>\n<p>By default bacula is set to use the <em>PostgreSQL<\/em>. The the following command is used to enable MySQL as the default. When you get the menu, select <em><strong>1<\/strong><\/em><\/p>\n<p><strong>#] <em>alternatives &#8211;config libbaccats.so<\/em><\/strong><\/p>\n<p>Let us make a two folders in the server. This is where we can plan to backup and restore files and folders. Ensure this is in a partition that has huge space to store all backups<br \/>\n<strong>#] <em>mkdir -p \/bacula\/backup \/bacula\/restore<\/em><\/strong><br \/>\nLet us assign the correct permissions<br \/>\n<strong>#]<\/strong><em><strong> chown -R bacula:bacula \/bacula<\/strong><\/em><br \/>\n<strong>#]<\/strong><em><strong> chmod -R 700 \/bacula<\/strong><\/em><\/p>\n<p>The server installation and setup is kind of done. Now we need to configure the server.<\/p>\n<p>We will start with the Director.<br \/>\nOpen the file bacula-dir.conf using an editor<\/p>\n<p>Ensure the last line is added to the below block<\/p>\n<p><em>Director { # define myself<\/em><br \/>\n<em> Name = bacula-dir<\/em><br \/>\n<em> DIRport = 9101 # where we listen for UA connections<\/em><br \/>\n<em> QueryFile = &#8220;\/etc\/bacula\/query.sql&#8221;<\/em><br \/>\n<em> WorkingDirectory = &#8220;\/var\/spool\/bacula&#8221;<\/em><br \/>\n<em> PidDirectory = &#8220;\/var\/run&#8221;<\/em><br \/>\n<em> Maximum Concurrent Jobs = 1<\/em><br \/>\n<em> Password = &#8220;@@DIR_PASSWORD@@&#8221; # Console password<\/em><br \/>\n<em> Messages = Daemon<\/em><br \/>\n<strong><em> DirAddress = 127.0.0.1<\/em><\/strong><br \/>\n<em> }<\/em><br \/>\n===== ==<\/p>\n<p>Now we need to create a &#8220;Job&#8221; to backup the localhost. Find the Name parameter in defined Job that reads &#8220;BackupClient1&#8221; and replace it with &#8220;BackupLocalFiles&#8221;<\/p>\n<p>== === =<\/p>\n<p><em>Job {<\/em><br \/>\n<em><strong> #<\/strong>Name = &#8220;BackupClient1&#8221;<\/em><br \/>\n<em> Name = &#8220;<strong>BackupLocalFiles<\/strong>&#8220;<\/em><br \/>\n<em> JobDefs = &#8220;DefaultJob&#8221;<\/em><br \/>\n<em> }<\/em><\/p>\n<p>== === =<\/p>\n<p>Now you may want to change the default location of where files should be restored from &#8220;\/tmp\/bacula-restores&#8221; to &#8220;<strong>\/bacula\/restore<\/strong>&#8221; and change the Job name &#8220;RestoreFiles&#8221; to &#8220;RestoreLocalFiles&#8221; so that it make meaning.<\/p>\n<p>====== =====<\/p>\n<p>Job {<br \/>\nName = &#8220;<strong>RestoreLocalFiles<\/strong>&#8221;<br \/>\nType = Restore<br \/>\nClient=BackupServer-fd<br \/>\nFileSet=&#8221;Full Set&#8221;<br \/>\nStorage = File<br \/>\nPool = Default<br \/>\nMessages = Standard<br \/>\n<strong>Where = \/bacula\/restore<\/strong><br \/>\n}<\/p>\n<p>====== =====<\/p>\n<p>You may want to edit the FileSet, named &#8220;Full Set&#8221; that defines the files that needs to be backed from the localhost. In this example we will backup the folder \/home\/user1. Ensure gzip compression is used, and only \/home folder is backed.<\/p>\n<p>======================= ======<br \/>\n<em>FileSet {<\/em><br \/>\n<em> Name = &#8220;Full Set&#8221;<\/em><br \/>\n<em> Include {<\/em><br \/>\n<em> Options {<\/em><br \/>\n<em> signature = MD5<\/em><br \/>\n<em> compression = GZIP<\/em><br \/>\n<em> }<\/em><br \/>\n<em> <strong>File = \/data<\/strong><\/em><br \/>\n<em> }<\/em><br \/>\n<em> Exclude {<\/em><br \/>\n<em> File = <strong>\/bacula<\/strong><\/em><br \/>\n<em> }<\/em><br \/>\n<em> }<\/em><br \/>\n======================= ======<\/p>\n<p>In the Storage parameter with name as &#8220;File&#8221; ensure the address parameter has the value as the actual hostname resolvable to an IP by the localhost. Ensure we do not use the value &#8220;localhost&#8221;. My host&#8217;s FQN is myhost.mydomain.local<\/p>\n<p>===== ==== ===<br \/>\n<em>Storage {<\/em><br \/>\n<em> Name = File<\/em><br \/>\n<em> # Do not use &#8220;localhost&#8221; here<\/em><br \/>\n<em> Address = myhost.mydomain.local # N.B. Use a fully qualified name here<\/em><br \/>\n<em> SDPort = 9103<\/em><br \/>\n<em> Password = &#8220;@@SD_PASSWORD@@&#8221;<\/em><br \/>\n<em> Device = FileStorage<\/em><br \/>\n<em> Media Type = File<\/em><br \/>\n<em> }<\/em><\/p>\n<p>===== ==== ===<\/p>\n<p>In the catelog section named &#8220;MyCatalog&#8221; ensure the correct password for for the dbname, dbuser and password is used<\/p>\n<p>====*====== ===<\/p>\n<p><em>Catalog {<\/em><br \/>\n<em> Name = MyCatalog<\/em><br \/>\n<em> # Uncomment the following line if you want the dbi driver<\/em><br \/>\n<em> # dbdriver = &#8220;dbi:postgresql&#8221;; dbaddress = 127.0.0.1; dbport =<\/em><br \/>\n<em> dbname = &#8220;<strong>bacula<\/strong>&#8220;; dbuser = &#8220;<strong>bacula<\/strong>&#8220;; dbpassword = &#8220;<strong>my_bacula_pw<\/strong>&#8220;<\/em><br \/>\n<em> }<\/em><\/p>\n<p>====*====== ===<\/p>\n<p>In the Pool definition named &#8220;File&#8221;, it will be good to use a &#8220;Label Format&#8221; parameter to identify the host that is stored. For example &#8220;myLocalhost-&#8221;<\/p>\n<p>===== === == ==== ==<br \/>\n<em>Pool {<\/em><br \/>\n<em> Name = File<\/em><br \/>\n<em> Pool Type = Backup<\/em><br \/>\n<em> <strong>Label Format = myLocalhost-<\/strong><\/em><br \/>\n<em> Recycle = yes # Bacula can automatically recycle Volumes<\/em><br \/>\n<em> AutoPrune = yes # Prune expired volumes<\/em><br \/>\n<em> Volume Retention = 365 days # one year<\/em><br \/>\n<em> Maximum Volume Bytes = 50G # Limit Volume size to something reasonable<\/em><br \/>\n<em> Maximum Volumes = 100 # Limit number of Volumes in Pool<\/em><br \/>\n<em> }<\/em><br \/>\n===== === == ==== ==<\/p>\n<p>Now we are in a position to check if there are any syntax error in the configuration file by running the following command:<br \/>\n<strong>]# <em>sudo bacula-dir -tc \/etc\/bacula\/bacula-dir.conf<\/em><\/strong><\/p>\n<p>Check for any error message<\/p>\n<p style=\"text-align: center;\">**************** Storage Daemon configuration ************<\/p>\n<p>The configuration file for the storage daemon is <em>bacula-sd.conf.\u00a0<\/em>Since the storage server is also the same server, add the hostname of the same server in Storage parameter named &#8220;BackupServer-sd&#8221;. This is done by adding a line &#8220;SDAddress = myhost.mydomain.local&#8221;<\/p>\n<p>==== === === ===<br \/>\n<em>Storage { # definition of myself<\/em><br \/>\n<em> Name = BackupServer-sd<\/em><br \/>\n<em> SDPort = 9103 # Director&#8217;s port<\/em><br \/>\n<em> WorkingDirectory = &#8220;\/var\/lib\/bacula&#8221;<\/em><br \/>\n<em> Pid Directory = &#8220;\/var\/run\/bacula&#8221;<\/em><br \/>\n<em> Maximum Concurrent Jobs = 20<\/em><br \/>\n<em> <strong>SDAddress = myhost.mydomain.local<\/strong><\/em><br \/>\n<em> }<\/em><br \/>\n==== === === ===<\/p>\n<p>In the Device parameter named &#8220;FileStorage&#8221; ensure the place where backup is stored is changed to &#8220;Archive Device = \/bacula\/backup&#8221;<\/p>\n<p>=== === === ===<br \/>\n<em>Device {<\/em><br \/>\n<em> Name = FileStorage<\/em><br \/>\n<em> Media Type = File<\/em><br \/>\n<em> <strong>Archive Device = \/bacula\/backup<\/strong><\/em><br \/>\n<em> LabelMedia = yes; # lets Bacula label unlabeled media<\/em><br \/>\n<em> Random Access = Yes;<\/em><br \/>\n<em> AutomaticMount = yes; # when device opened, read it<\/em><br \/>\n<em> RemovableMedia = no;<\/em><br \/>\n<em> AlwaysOpen = no;<\/em><br \/>\n<em> }<\/em><br \/>\n=== === === ===<\/p>\n<p>Now verify the storage configuration:<br \/>\n<strong> # sudo bacula-sd -tc \/etc\/bacula\/bacula-sd.conf<\/strong><\/p>\n<p>Now it is time to change bacula-dir passwords used in files.<\/p>\n<p><strong>]#<\/strong> <em><strong>sudo sed -i &#8220;s\/@@DIR_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bacula-dir.conf<\/strong><\/em><br \/>\n<strong>]#<\/strong><em><strong> sudo sed -i &#8220;s\/@@DIR_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bconsole.conf<\/strong><\/em><br \/>\n<strong>]#<\/strong><em><strong> sudo sed -i &#8220;s\/@@SD_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bacula-sd.conf<\/strong><\/em><br \/>\n<strong>]#<\/strong><em><strong> sudo sed -i &#8220;s\/@@SD_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bacula-dir.conf<\/strong><\/em><br \/>\n<strong>]#<\/strong><em><strong> sudo sed -i &#8220;s\/@@FD_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bacula-dir.conf<\/strong><\/em><br \/>\n<strong> ]#<\/strong> <em><strong>sudo sed -i &#8220;s\/@@FD_PASSWORD@@\/my_bacula_pw\/&#8221; \/etc\/bacula\/bacula-fd.conf<\/strong><\/em><\/p>\n<p style=\"text-align: center;\">======************=======<\/p>\n<p>Now we are ready to start Bacula<\/p>\n<p><strong>]# <em>sudo systemctl start bacula-dir<\/em><\/strong><br \/>\n<strong>]# <em>sudo systemctl start bacula-sd<\/em><\/strong><br \/>\n<strong>]# <em>sudo systemctl start bacula-fd<\/em><\/strong><\/p>\n<p><strong>]# <em>sudo systemctl enable bacula-dir<\/em><\/strong><br \/>\n<strong>]# <em>sudo systemctl enable bacula-sd<\/em><\/strong><br \/>\n<strong>]# <em>sudo systemctl enable bacula-fd<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>******* ******* ********<\/p>\n<p>Installation is complete now you can start managing the backup application by using the<br \/>\nIMP :Volume Retention : As a consequence, the minimum Volume Retention period should be at twice the interval of your Full backups.<\/p>\n<p>&nbsp;<\/p>\n<p>Process to test backup and restore can be found &#8220;<a href=\"http:\/\/shijuvarghese.com\/?p=903\">here<\/a>&#8220;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Bacula is a very powerful enterprise level backup solution which can backup localhost, and even remote host via network. It has these components Director Storage <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=396\" title=\"Bacula Backup Systems (Server)\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":408,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-396","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backup"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=396"}],"version-history":[{"count":11,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/396\/revisions"}],"predecessor-version":[{"id":912,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/396\/revisions\/912"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/408"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=396"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}