{"id":7060,"date":"2017-10-11T18:09:35","date_gmt":"2017-10-11T10:09:35","guid":{"rendered":"http:\/\/rmohan.com\/?p=7060"},"modified":"2017-10-11T18:09:35","modified_gmt":"2017-10-11T10:09:35","slug":"backup-with-rsnapshot-tool","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7060","title":{"rendered":"Backup with Rsnapshot tool"},"content":{"rendered":"<p><strong>Backup with Rsnapshot tool<\/strong><\/p>\n<p>How To Set Red hat \/ CentOS Linux Remote Backup \/ Snapshot Server<\/p>\n<p>A. rsnapshot is easy, reliable and disaster recovery backup solution. It is a remote backup program that uses rsync to take backup snapshots of filesystems. It uses hard links to save space on disk and offers following features:<br \/>\nFilesystem snapshot &#8211; for local or remote systems.<br \/>\nDatabase backup &#8211; MySQL backup<br \/>\nSecure &#8211; Traffic between remote backup server is always encrypted using openssh<br \/>\nFull backup &#8211; plus incrementals<br \/>\nEasy to restore &#8211; Files can restored by the users who own them, without the root user getting involved.<br \/>\nAutomated backup &#8211; Runs in background via cron.<br \/>\nBandwidth friendly &#8211; rsync used to save bandwidth<br \/>\nSample setup<\/p>\n<p>snapshot.example.com &#8211; HP box with RAID 6 configured with Red Hat \/ CentOS Linux act as backup server for other clients.<br \/>\nDNS ns1.example.com &#8211; Red Hat server act as primary name server.<br \/>\nDNS ns2.example.com &#8211; Red Hat server act as secondary name server.<br \/>\nwww.example.com &#8211; Red Hat running Apache web server.<br \/>\nmysql.example.com &#8211; Red Hat mysql server.<br \/>\nInstall rsnapshot<\/p>\n<p>Login to snapshot.example.com. Download rsnapshot rpm file, enter:<br \/>\n# cd \/tmp<br \/>\n# wget http:\/\/www.rsnapshot.org\/downloads\/rsnapshot-1.3.0-1.noarch.rpm<br \/>\n# wget http:\/\/www.rsnapshot.org\/downloads\/rsnapshot-1.3.0-1.noarch.rpm.md5<\/p>\n<p># cd \/tmp<br \/>\n# wget http:\/\/www.rsnapshot.org\/downloads\/rsnapshot-1.3.0-1.noarch.rpm<br \/>\n# wget http:\/\/www.rsnapshot.org\/downloads\/rsnapshot-1.3.0-1.noarch.rpm.md5<\/p>\n<p>Configure rsnapshot<\/p>\n<p>You need to perform following steps<br \/>\nStep # 1: Configure password less login<\/p>\n<p>To perform remote backup you need to setup password less login using openssh. Create ssh rsa key and upload they to all servers using scp (note you are overwriting ~\/ssh\/authorized_keys2 files). You need to type following commands on snapshot.example.com server:<br \/>\n# ssh-keygen -t rsa<br \/>\n# scp .ssh\/id_rsa.pub root@ns1.example.com:.ssh\/authorized_keys2<br \/>\n# scp .ssh\/id_rsa.pub root@ns2.example.com:.ssh\/authorized_keys2<br \/>\n# scp .ssh\/id_rsa.pub root@www.example.com:.ssh\/authorized_keys2<br \/>\n# scp .ssh\/id_rsa.pub root@mysql.example.com:.ssh\/authorized_keys2<br \/>\nStep # 2: Configure rsnapshot<\/p>\n<p>The default configuration file is located at \/etc\/rsnapshot.conf. Open configuration file using a text editor, enter:<br \/>\n# vi \/etc\/rsnapshot.conf<\/p>\n<p>Configuration rules<\/p>\n<p>You must follow two configuration rules:<br \/>\nrsnapshot config file requires tabs between elements.<br \/>\nAll directories require a trailing slash. For example, \/home\/ is correct way to specify directory, but \/home is wrong.<br \/>\nFirst, specify root directory to store all snapshots such as \/snapshots\/ or \/dynvol\/snapshot\/ as per your RAID setup, enter:<br \/>\nsnapshot_root \/raiddisk\/snapshots\/<br \/>\nYou must separate snapshot_root and \/raiddisk\/snapshots\/ by a [tab] key i.e. type snapshot_root hit [tab] key once and type \/raiddisk\/snapshots\/.<br \/>\nDefine snapshot intervals<\/p>\n<p>You need to specify backup intervals i.e. specify hourly, daily, weekly and monthly intervals:<br \/>\ninterval hourly 6<br \/>\ninterval daily 7<br \/>\ninterval weekly 4<br \/>\ninterval monthly 3<br \/>\nThe line &#8220;interval hourly 6&#8221; means 6 hourly backups a day. Feel free to adapt configuration as per your backup requirements and snapshot frequency .<\/p>\n<p>Remote backup directories<\/p>\n<p>To backup \/var\/named\/ and \/etc\/ directory from ns1.example.com and ns2.example.com, enter:<br \/>\nbackup root@ns1.example.com:\/etc\/ ns1.example.com\/<br \/>\nbackup root@ns1.example.com:\/var\/named\/ ns1.example.com\/<br \/>\nbackup root@ns2.example.com:\/etc\/ ns2.example.com\/<br \/>\nbackup root@ns2.example.com:\/var\/named\/ ns2.example.com\/<br \/>\nTo backup \/var\/www\/, \/var\/log\/httpd\/ and \/etc\/ directory from www.example.com, enter<br \/>\nbackup root@www.example.com:\/var\/www\/ www.example.com\/<br \/>\nbackup root@www.example.com:\/etc\/ www.example.com\/<br \/>\nbackup root@www.example.com:\/var\/log\/httpd\/ www.example.com\/<br \/>\nTo backup mysql database files stored at \/var\/lib\/mysql\/, enter:<br \/>\nbackup root@mysql.example.com:\/var\/lib\/mysql\/ mysql.example.com\/dbdump\/<br \/>\nSave and close the file. To test your configuration, enter:<br \/>\n# rsnapshot configtest<br \/>\nSample output:<br \/>\nSyntax OK<\/p>\n<p>Schedule cron job<\/p>\n<p>Create \/etc\/cron.d\/rsnapshot cron file. Following values used correspond to the examples in \/etc\/rsnapshot.conf.<br \/>\n0 *\/4 * * *         \/usr\/bin\/rsnapshot hourly<br \/>\n50 23 * * *         \/usr\/bin\/rsnapshot daily<br \/>\n40 23 * * 6         \/usr\/bin\/rsnapshot weekly<br \/>\n30 23 1 * *         \/usr\/bin\/rsnapshot monthly<br \/>\nSave and close the file. Now rsnapshot will work as follows to backup files from remote boxes:<br \/>\n6 hourly backups a day (once every 4 hours, at 0,4,8,12,16,20)<br \/>\n1 daily backup every day, at 11:50PM<br \/>\n1 weekly backup every week, at 11:40PM, on Saturdays (6th day of week)<br \/>\n1 monthly backup every month, at 11:30PM on the 1st day of the month<br \/>\nHow do I see backups?<\/p>\n<p>To see backup change directory to<br \/>\n# cd \/raiddisk\/snapshots\/<br \/>\n# ls -l<br \/>\nSample output:<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-04 06:04 daily.0<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-03 06:04 daily.1<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-02 06:03 daily.2<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-01 06:02 daily.3<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-30 06:02 daily.4<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-29 06:05 daily.5<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-28 06:04 daily.6<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 18:05 hourly.0<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 15:06 hourly.1<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 12:06 hourly.2<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 09:05 hourly.3<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 06:04 hourly.4<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 03:04 hourly.5<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-05 00:05 hourly.6<br \/>\ndrwxr-xr-x 4 root root 4096 2008-07-04 21:05 hourly.7<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-22 06:04 weekly.0<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-15 09:05 weekly.1<br \/>\ndrwxr-xr-x 4 root root 4096 2008-06-08 06:04 weekly.2<\/p>\n<p>How do I restore backup?<\/p>\n<p>Let us say you would like to restore a backup for www.example.com. Type the command as follows (select day and date from ls -l output):<br \/>\n# cd \/raiddisk\/snapshots\/<br \/>\n# ls -l<br \/>\n# cd hourly.0\/www.example.com\/<br \/>\n# scp -r var\/www\/ root@www.example.com:\/var\/www\/<br \/>\n# scp -r etc\/httpd\/ root@www.example.com:\/etc\/httpd\/<br \/>\nHow do I exclude files from backup?<\/p>\n<p>To exclude files from backup, open rsnapshot.conf file and add following line:<br \/>\nexclude_file \/etc\/rsnapshot.exclude.www.example.com<br \/>\nCreate \/etc\/rsnapshot.exclude.www.example.com as follows:<br \/>\n\/var\/www\/tmp\/<br \/>\n\/var\/www\/*.cache<br \/>\nFurther readings:<\/p>\n<p>man rsnaspshot, ssh, ssh-keygen<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Backup with Rsnapshot tool<\/p>\n<p>How To Set Red hat \/ CentOS Linux Remote Backup \/ Snapshot Server<\/p>\n<p>A. rsnapshot is easy, reliable and disaster recovery backup solution. It is a remote backup program that uses rsync to take backup snapshots of filesystems. It uses hard links to save space on disk and offers following features: [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7060"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7060"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7060\/revisions"}],"predecessor-version":[{"id":7061,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7060\/revisions\/7061"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}