{"id":27,"date":"2013-11-25T22:27:39","date_gmt":"2013-11-25T22:27:39","guid":{"rendered":"http:\/\/etapien.com\/guides\/?p=27"},"modified":"2020-08-24T14:22:37","modified_gmt":"2020-08-24T19:22:37","slug":"how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu","status":"publish","type":"post","link":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/","title":{"rendered":"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu"},"content":{"rendered":"<p>Say you want to backup 2 remote linux servers, a great tool for this is rsnapshot. So we&#8217;re going to backup those 2 servers and will make incremental snapshots of local and remote filesystems for any number of machines on 2nd hard disk located at \/disk1 ( \/dev\/sdb2).<\/p>\n<p>rsnapshot is perfect open source solution for making backups on local system. It supports both remote and local systems. From the man page:<\/p>\n<blockquote><p>rsnapshot saves much more disk space than you might imagine. The amount of space required is roughly the size of one full backup, plus a copy of each additional file that is changed. rsnapshot makes extensive use of hard links, so if the file doesn\u2019t change, the next snapshot is simply a hard link to the exact same file. The following instructions are compatible with both Debian and Ubuntu Linux.<\/p><\/blockquote>\n<h2>Required software \/ setup on local backup system<\/h2>\n<ol>\n<li>rsnapshot<\/li>\n<li>rsync<\/li>\n<li>ssh client<\/li>\n<li>2nd hard disk ( RAID array is suggested) &#8211; you can also use primary hard disk<\/li>\n<li>Password less login configured using ssh keys<\/li>\n<li>\/disk1\/backup &#8211; Backup directory<\/li>\n<li>\/disk1\/backup\/server1 &#8211; Backup directory for remote server called server1<\/li>\n<li>\/disk1\/backup\/server2 &#8211; Backup directory for remote server called server2<\/li>\n<li>\/disk1\/backup\/localhost &#8211; Backup directory for local server<\/li>\n<\/ol>\n<h2>Required software on remote server<\/h2>\n<ol>\n<li>OpenSSH sshd server<\/li>\n<li>Password less login configured using ssh keys<\/li>\n<\/ol>\n<h2>Step #1: Install rsync and rsnapshot software<\/h2>\n<p>Use apt-get command, enter:<br \/>\n<code>$ sudo apt-get install rsync rsnapshot<\/code><\/p>\n<h2>Step #2: Configure passwordless login \/ public key based login<\/h2>\n<p>Type the following command<br \/>\n<code># ssh-keygen -t rsa<br \/>\n# scp .ssh\/id_rsa.pub root@remotebox1.server.com:.ssh\/authorized_keys2<br \/>\n# scp .ssh\/id_rsa.pub root@remotebox2.server.com:.ssh\/authorized_keys2 <\/code><br \/>\nSee how to configure <a href=\"http:\/\/www.cyberciti.biz\/tips\/ssh-public-key-based-authentication-how-to.html\">RSA<\/a> \/ <a href=\"http:\/\/www.cyberciti.biz\/faq\/ssh-password-less-login-with-dsa-publickey-authentication\/\">DSA<\/a> SSH public key based authentication.<\/p>\n<h2>Step #3: Configure rsnapshot utility<\/h2>\n<p>The configuration file is located at \/etc\/rsnapshot.conf. The configuration file requires tabs between elements and all drectories require a trailing slash. Just open config file using a text editor such as vi or gedit:<br \/>\n<code># vi \/etc\/rsnapshot.conf<\/code><br \/>\nOR<br \/>\n<code>$ sudo vi \/etc\/rsnapshot.conf<\/code><br \/>\nSet snapshots root directory:<\/p>\n<pre>snapshot_root\t\/disk1\/backup\/<\/pre>\n<p>Note you must separate snapshot_root and \/disk1\/ by a [tab] key i.e. type snapshot_root hit [tab] key once and type \/disk1\/backup\/. All snapshots will be stored under this root directory (\/disk1\/backup\/).<\/p>\n<h3>Configure backup policy<\/h3>\n<p>You can make hourly, daily, weekly or monthly snapshots of local and remote systems. To make a snapshot every four hours (six times a day) and keep a second set, which are taken once a day, and stored for a seven days, enter:<\/p>\n<pre>interval    hourly  6\r\ninterval    daily   7<\/pre>\n<p>Feel free to adapt configuration as per your backup needs.<\/p>\n<h3>Specify local and remote backup directories<\/h3>\n<p>Find out comments that read as follows:<\/p>\n<pre>###############################\r\n### BACKUP POINTS \/ SCRIPTS ###\r\n###############################<\/pre>\n<p>You need to comment out \/ delete default backup directories. To make snapshots for \/home\/, \/etc\/, \/webroot\/ directories to \/disk1\/backup\/localhost, enter:<\/p>\n<pre>backup\t\/home\/\tlocalhost\/\r\nbackup\t\/etc\/\tlocalhost\/\r\nbackup\t\/webroot\/\tlocalhost\/<\/pre>\n<p>To backup remote server1 \/home\/, \/etc\/, \/var\/spool\/mail\/, \/webroot\/ directories to \/disk1\/backup\/server1, enter:<\/p>\n<pre>backup\troot@remotebox1.server.com:\/home\/\tserver1\/\r\nbackup\troot@remotebox1.server.com:\/etc\/\tserver1\/\r\nbackup\troot@remotebox1.server.com:\/webroot\/\tserver1\/\r\nbackup\troot@remotebox1.server.com:\/var\/spool\/mail\/\tserver1\/\r\nbackup\troot@remotebox2.server.com:\/home\/\tserver2\/<\/pre>\n<p>Save and close the file.<\/p>\n<h3>Test your config file for errors<\/h3>\n<p>Type the following to test your configuration file for errors<br \/>\n<code># rsnapshot configtest<\/code><br \/>\nOutput:<\/p>\n<pre>Syntax OK<\/pre>\n<p>You can also run rsnapshot in a test mode to display its action:<br \/>\n<code># rsnapshot -t hourly<\/code><\/p>\n<h2>Step #4: Run rsnapshot for first time<\/h2>\n<p>To run first time, enter:<br \/>\n<code># rsnapshot hourly<\/code><\/p>\n<h2>Step #5: Configure cron job<\/h2>\n<p>Edit \/etc\/cron.d\/rsnapshot file to setup backup snapshot job. This is a sample cron file for rsnapshot. The values used correspond to the examples in \/etc\/rsnapshot.conf. There you can also set the backup points and many other things. To activate this cron file you have to uncomment the lines below.<br \/>\nFeel free to adapt it to your needs.<\/p>\n<pre>0 *\/4         * * *           root    \/usr\/bin\/rsnapshot hourly\r\n30 3          * * *           root    \/usr\/bin\/rsnapshot daily\r\n0  3          * * 1           root    \/usr\/bin\/rsnapshot weekly\r\n30 2          1 * *           root    \/usr\/bin\/rsnapshot monthly<\/pre>\n<p>See <a href=\"http:\/\/www.cyberciti.biz\/faq\/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses\/\">crontab related faq<\/a> for more information about cronjob under UNIX \/ Linux.<\/p>\n<h2>How do I exclude files from backup?<\/h2>\n<p>rsnapshot allows you to set the include and exclude parameters, if enabled, simply get passed directly to rsync. If you have multiple include\/exclude patterns, put each one on a separate line. For example,<br \/>\n<code>exclude_file \/etc\/rsnapshot.server1.conf<\/code><br \/>\nAppend exclude file list to \/etc\/rsnapshot.server1.conf:<br \/>\n<code># vi \/etc\/rsnapshot.server1.conf<\/code><br \/>\nExclude files matching pattern from backup:<br \/>\n<code><br \/>\nvar\/lib\/php\/session\/*<br \/>\n\/var\/spool\/mail\/nobody\/*<br \/>\ncache\/wp-cache-*.????<br \/>\n\/var\/logs\/apache\/access.log.*<br \/>\n\/var\/logs\/apache\/error.log.*<br \/>\n\/linux-kernel\/*<br \/>\n\/tmp\/cache\/*<br \/>\n\/var\/lib\/mysql\/mysql.sock*<br \/>\n\/tmp\/php.socket-*<br \/>\n\/tmp\/*socket*<\/code><br \/>\nSave and close the file.<\/p>\n<h2>How do I backup remote MySQL database?<\/h2>\n<p>You can backup default database directory \/var\/lib\/mysql. However, you can backup remote or local MySQL database with the following script:<\/p>\n<pre>#!\/bin\/sh\r\nNOW=$(date +\"%d-%m-%Y\")\r\n# set mysql login info\r\nMUSER=\"MySQL-UserNAME\"                # Username\r\nMPASS=\"MySQL-SERVER-PASSWORD\"   # Password\r\nMHOST=\"MySQL-SERVER-IP-ADDRESS\"  # Server Name\r\n# guess binary names \r\nMYSQL=\"$(which mysql)\"\r\nMYSQLDUMP=\"$(which mysqldump)\"\r\nGZIP=\"$(which gzip)\"\r\n\r\n# get all db names \r\nDBS=\"$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')\"\r\nfor db in $DBS\r\ndo\r\n FILE=mysql-$db.$NOW-$(date +\"%T\").gz\r\n $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 &gt; $FILE\r\ndone<\/pre>\n<p>Now add following line to \/etc\/rsnapshot.conf file:<br \/>\n<code>backup_script \/root\/scripts\/mysql.backup.sh server1\/mysql\/<\/code><\/p>\n<h2>How do I restore backup?<\/h2>\n<p>You can simply copy back file using regular scp \/ rsync command. In this example, restore all *.html file to remote web server called www-03.example.com:<\/p>\n<pre>\u00a0\r\nrsync -av *.html user@www-03.example.com:\/home\/httpd\/example\/html\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is a way to backup remote Linux servers using rsnapshot, which can do incremental backups.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[13,15,14,16],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos\" \/>\n<meta property=\"og:description\" content=\"Here is a way to backup remote Linux servers using rsnapshot, which can do incremental backups.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Howtos\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-25T22:27:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-24T19:22:37+00:00\" \/>\n<meta name=\"author\" content=\"Etapien\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etapien\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/\",\"url\":\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/\",\"name\":\"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos\",\"isPartOf\":{\"@id\":\"https:\/\/etapien.com\/guides\/#website\"},\"datePublished\":\"2013-11-25T22:27:39+00:00\",\"dateModified\":\"2020-08-24T19:22:37+00:00\",\"author\":{\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\"},\"breadcrumb\":{\"@id\":\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/etapien.com\/guides\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/etapien.com\/guides\/#website\",\"url\":\"https:\/\/etapien.com\/guides\/\",\"name\":\"Tech Howtos\",\"description\":\"Tech related useful howtos\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/etapien.com\/guides\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\",\"name\":\"Etapien\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"caption\":\"Etapien\"},\"url\":\"https:\/\/etapien.com\/guides\/author\/Etapien\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos","og_description":"Here is a way to backup remote Linux servers using rsnapshot, which can do incremental backups.","og_url":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/","og_site_name":"Tech Howtos","article_published_time":"2013-11-25T22:27:39+00:00","article_modified_time":"2020-08-24T19:22:37+00:00","author":"Etapien","twitter_misc":{"Written by":"Etapien","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/","url":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/","name":"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu - Tech Howtos","isPartOf":{"@id":"https:\/\/etapien.com\/guides\/#website"},"datePublished":"2013-11-25T22:27:39+00:00","dateModified":"2020-08-24T19:22:37+00:00","author":{"@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424"},"breadcrumb":{"@id":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/etapien.com\/guides\/how-to-backup-remote-linux-servers-using-rnapshot-in-debian-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/etapien.com\/guides\/"},{"@type":"ListItem","position":2,"name":"How to backup remote linux servers using rnapshot in Debian \/ Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/etapien.com\/guides\/#website","url":"https:\/\/etapien.com\/guides\/","name":"Tech Howtos","description":"Tech related useful howtos","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/etapien.com\/guides\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424","name":"Etapien","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","caption":"Etapien"},"url":"https:\/\/etapien.com\/guides\/author\/Etapien\/"}]}},"_links":{"self":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/27"}],"collection":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":6,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/27\/revisions\/64"}],"wp:attachment":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}