{"id":251,"date":"2017-05-31T11:09:38","date_gmt":"2017-05-31T09:09:38","guid":{"rendered":"http:\/\/owncloud.gonscak.sk\/?p=251"},"modified":"2017-05-31T11:09:38","modified_gmt":"2017-05-31T09:09:38","slug":"bareos-on-centos-7-powerful-backup-tool","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=251","title":{"rendered":"Bareos on Centos 7 &#8211; powerful backup tool"},"content":{"rendered":"<p>Today I met with backup problem. I nee to find and set up solution for backup and possible restore of files in windows or linux. I heard about bacula, but after som searching and reading, I choose a new fork of bacula &#8211; <a href=\"https:\/\/www.bareos.org\/en\/\">bareos<\/a>.<\/p>\n<h2>Installing Bareos itself<\/h2>\n<p>So I install it on new, clean vm centos 7. At first define a hostname:<\/p>\n<pre>hostnamectl set-hostname bareos-ba<\/pre>\n<p>Next, add a bareos repository:<\/p>\n<pre>cd \/etc\/yum.repos.d\/\nwget http:\/\/download.bareos.org\/bareos\/release\/latest\/CentOS_7\/bareos.repo\nyum install bareos -y<\/pre>\n<p>Next, we can use MariaDB-server for backend od bareos:<\/p>\n<pre>yum install mariadb-server -y\nsystemctl start mariadb.service\nsystemctl enable mariadb.servic<\/pre>\n<p>Now, we create and mount a file-storage, when bareos will save the data:<\/p>\n<pre>fdisk \/dev\/vda\n...\nmkfs.xfs \/dev\/vda1\nmkdir \/var\/backups\nmount \/dev\/vda1 \/var\/backups\/\nchown bareos:bareos -R \/var\/backups\/\ndf -h\n...\nFilesystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Size\u00a0 Used Avail Use% Mounted on\n\/dev\/vda1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 32G\u00a0\u00a0 33M\u00a0\u00a0 32G\u00a0\u00a0 1% \/var\/backups<\/pre>\n<p>Edit \/etc\/fstab to make this mount permanent.<br \/>\nNow, we can create a new bareos database with pre-defined scripts:<\/p>\n<pre>[root@bareos-ba]#\/usr\/lib\/bareos\/scripts\/create_bareos_database\nCreating mysql database\nCreating of bareos database succeeded.\n[root@bareos-ba]# \/usr\/lib\/bareos\/scripts\/make_bareos_tables\nMaking mysql tables\nCreation of Bareos MySQL tables succeeded.\n[root@bareos-ba]# \/usr\/lib\/bareos\/scripts\/grant_bareos_privileges\nGranting mysql tables\nPrivileges for user bareos granted ON database bareos.<\/pre>\n<p>Now, we can check our default configuration with:<\/p>\n<pre>su bareos -s \/bin\/sh -c \"\/usr\/sbin\/bareos-dir -t\"\nsu bareos -s \/bin\/sh -c \"\/usr\/sbin\/bareos-sd -t\"\nbareos-fd -t<\/pre>\n<p>If you are using firewall, for bareos server open this ports:<\/p>\n<pre>firewall-cmd --zone=public --add-port=9101\/tcp --permanent\nfirewall-cmd --zone=public --add-port=9102\/tcp --permanent\nfirewall-cmd --zone=public --add-port=9103\/tcp --permanent\n#http only if you want web-gui for baores\nfirewall-cmd --zone=public --add-service=http --permanent\nfirewall-cmd --reload\nfirewall-cmd --list-all\n#public (active)\n# - services: http ssh\n# - ports: 5666\/tcp 9103\/tcp 9101\/tcp 161\/udp 9102\/tcp\n<\/pre>\n<h3>This step is only for bareos WebUI. If you don&#8217;t need this, skip it.<\/h3>\n<pre>yum install bareos-webui -y\nsetsebool -P httpd_can_network_connect on\nsystemctl start httpd.service\nsystemctl enable httpd.service<\/pre>\n<p>Edit conf file and set FQDN for this host:<\/p>\n<pre>vim \/etc\/bareos-webui\/directors.ini\n- diraddress = \"bareos-ba.example.com\"<\/pre>\n<p>Copy example admin console config:<\/p>\n<pre>cp \/etc\/bareos\/bareos-dir.d\/console\/admin.conf.example \/etc\/bareos\/bareos-dir.d\/console\/admin.conf\nchown bareos:bareos \/etc\/bareos\/bareos-dir.d\/console\/admin.conf<\/pre>\n<h3>Setting up a storage for bareos director<\/h3>\n<p>At first, we must add our previously created and mounted disk to our bareos-storage daemon and then add it to bareos-director daemon for using it and working.<\/p>\n<pre>cp \/etc\/bareos\/bareos-sd.d\/device\/FileStorage.conf \/etc\/bareos\/bareos-sd.d\/device\/backups.conf\nchown bareos:bareos \/etc\/bareos\/bareos-sd.d\/device\/backups.conf\nvim \/etc\/bareos\/bareos-sd.d\/device\/backups.conf\n - change archive device and the name:\nArchive Device = \/var\/backups\nName = Backups<\/pre>\n<pre>cp \/etc\/bareos\/bareos-dir.d\/storage\/File.conf \/etc\/bareos\/bareos-dir.d\/storage\/backups.conf\nchown bareos:bareos \/etc\/bareos\/bareos-dir.d\/storage\/backups.conf\nvim \/etc\/bareos\/bareos-dir.d\/storage\/backups.conf\n - change Name and Device. Name must be the same as above:\nName = Backups\nDevice = Backups<\/pre>\n<p>Now we edit job definitions:<\/p>\n<pre>vim \/etc\/bareos\/bareos-dir.d\/jobdefs\/DefaultJob.conf\n - change Storage variable to ours above mentioned:\nStorage = Backups<\/pre>\n<p>Now again check bareos config files for error:<\/p>\n<pre>su bareos -s \/bin\/sh -c \"\/usr\/sbin\/bareos-dir -t\"\nsu bareos -s \/bin\/sh -c \"\/usr\/sbin\/bareos-sd -t\"\nbareos-fd -t<\/pre>\n<p>and restart (start) bareos:<\/p>\n<pre>service bareos-dir restart\nservice bareos-sd restart\nservice bareos-fd restart\nsystemctl enable bareos-dir.service\nsystemctl enable bareos-sd.service\nsystemctl enable bareos-fd.service<\/pre>\n<h3>Using bconsole and WEBui<\/h3>\n<p>Our webui is on address bellow. Default login nad pass is: admin\/admin<\/p>\n<pre>http:\/\/bareos-ba.globesy.sk\/bareos-webui\/<\/pre>\n<p>Our bareos console is avalaible via command bconsole:<\/p>\n<pre>[root@bareos-ba ~]# bconsole\nConnecting to Director localhost:9101\n1000 OK: bareos-dir Version: 16.2.4 (01 July 2016)\nEnter a period to cancel a command.\n*<\/pre>\n<p>bconsole is marked at the beginning with asterisk *<br \/>\nSome useful commands:<\/p>\n<pre>list storages\nAutomatically selected Catalog: MyCatalog\nUsing Catalog \"MyCatalog\"\n+-----------+---------+-------------+\n| StorageId | Name\u00a0\u00a0\u00a0 | AutoChanger |\n+-----------+---------+-------------+\n|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1 | File\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 |\n|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2 | Backups |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 |\n+-----------+---------+-------------+\nlist pools\nshow jobdefs\nshow filesets\nstatus dir\nstatus client=bareos-fd\n<\/pre>\n<p>Now we can start our first job &#8211; Selftest. So, run bconsole and continue:<\/p>\n<pre>bconsole\n*run\n- select job resource 3: backup-bareos-fs\n- yes =&gt; Job queued. JobId=1\n*wait jobid=1\n*messages\nquit<\/pre>\n<p>In messages we can see, that bareos backup almost 44MB of files. In our fileset of this Selftest, we can see bareos backup folder \/usb\/sbin:<\/p>\n<pre>cat \/etc\/bareos\/bareos-dir.d\/fileset\/SelfTest.conf<\/pre>\n<p>Now, we can restore this files. By default job of restore, it will be restored to \/tmp\/bareos-restores:<\/p>\n<pre>\u00a0cat \/etc\/bareos\/bareos-dir.d\/job\/RestoreFiles.conf<\/pre>\n<p>Run bconsole:<\/p>\n<pre>*restore all client=bareos-fd\n- select 5 for most recent backup\n- done\n- yes\nJob queued. JobId=2\n*wait jobid=2\n*messages\n..<\/pre>\n<p>We can see our restored files in \/tmp\/bareos-restores\/.<br \/>\n&nbsp;<\/p>\n ","protected":false},"excerpt":{"rendered":"<p>Today I met with backup problem. I nee to find and set up solution for backup and possible restore of files in windows or linux. I heard about bacula, but after som searching and reading, I choose a new fork of bacula &#8211; bareos. Installing Bareos itself So I install it on new, clean vm &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=251\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bareos on Centos 7 &#8211; powerful backup tool<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[71],"class_list":["post-251","post","type-post","status-publish","format-standard","hentry","category-centos","tag-bareos-centos-backup"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=251"}],"version-history":[{"count":0,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/251\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}