{"id":3904,"date":"2021-02-16T13:45:08","date_gmt":"2021-02-16T19:45:08","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=3904"},"modified":"2021-02-16T13:45:10","modified_gmt":"2021-02-16T19:45:10","slug":"configure-rsnapshot-on-ubuntu-server","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/configure-rsnapshot-on-ubuntu-server\/","title":{"rendered":"Configure rsnapshot on Ubuntu Server"},"content":{"rendered":"\n<p>rsnapshot is a utility that uses rsync to backup files locally or it can backup files from a remote server.  <\/p>\n\n\n\n<p>While trying to figure out a good solution for backing up an Ubuntu Server I decided to try rsnapshot, however since it can either create a local backup or pull a remote backup it needs to be configured to do that on the backup server side.  It does not &#8220;push&#8221; a backup to a backup server.<\/p>\n\n\n\n<p>Some helpful snippits from the man file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>rsnapshot will typically be invoked as root by a cron job, or series of cron jobs. It is possible, however, to run as any    arbitrary user with an alternate configuration file.<\/code>\n...\nUSAGE\n        rsnapshot can be used by any user, but for system-wide backups you will probably want to run it as root.\n...\nNOTES\n        Make sure your \/etc\/rsnapshot.conf file has all elements separated by tabs.  See\n        \/usr\/share\/doc\/rsnapshot\/examples\/rsnapshot.conf.default.gz for a working example file.\n <code>   Make sure you put a trailing slash on the end of all directory references.  If you don't, you may have extra directories    created in your snapshots.  For more information on how the trailing slash is handled, see the rsync(1) manpage.<\/code>\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>Scenario <\/p>\n\n\n\n<p>Host A runs xyz application and host B is the backup server.  We create a backup user on host A, host B then uses that user to ssh and rsync backups to itself.  <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create backup user<\/li><li>Configure rysnc to be used without a password<\/li><li>Setup SSH Key, aka Passwordless authentication (On backup server)<\/li><li>Setup rsnapshot config (On backup server)<\/li><li>Configure rsnapshot in crontab (On backup server)<\/li><li>Final Testing<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create backup user<\/h2>\n\n\n\n<p>The following commands are fairly straight forward.  Change backupuser to whatever you want to call your backup user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo useradd -m backupuser\npasswd backupuser\nsudo usermod -a -G sudo backupuser<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configure rysnc to be used without a password<\/h2>\n\n\n\n<p>We need to setup the backup user to be able to use &#8220;sudo rsync&#8221; without having to input the user password.  If we don&#8217;t use sudo we can&#8217;t access system files for backups.  And if we have to manually input the password every time rsync runs, then the backups would not be automatic.  The following link was helpful.  <\/p>\n\n\n\n<p><a href=\"https:\/\/unix.stackexchange.com\/questions\/325100\/proper-way-to-set-up-rsnapshot-over-ssh\">https:\/\/unix.stackexchange.com\/questions\/325100\/proper-way-to-set-up-rsnapshot-over-ssh<\/a><\/p>\n\n\n\n<p>All we need to do is create a file in \/etc\/sudoers.d\/username and then tell it we don&#8217;t need to enter a password when &#8220;sudo rsync&#8221; is run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/sudoers.d\/backupuser &lt;&lt;&lt;'backupuser ALL = (root) NOPASSWD: \/usr\/bin\/rsync'<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup SSH Key, aka Passwordless authentication (On backup server)<\/h2>\n\n\n\n<p>Log into the backup server<\/p>\n\n\n\n<p>Create SSH keys.  Note that since rsnapshot wants to run as root, we create the key and copy it as the root user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ssh-keygen<\/pre>\n\n\n\n<p>Accept all the defaults so we can login from the backup server without having to enter in a password.<\/p>\n\n\n\n<p>Copy ssh key to the server we are wanting to back up<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ssh-copy-id backupuser@ip<\/pre>\n\n\n\n<p>enter in the password and the the key should get copied it over.  Once complete, verify that you can login without having to enter in a password.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup rsnapshot config (On backup server)<\/h2>\n\n\n\n<p>Open up the rsnapshot config file and modify where appropriate.  \/etc\/rsnapshot.conf<\/p>\n\n\n\n<p>Change the path to where the snapshots are stored.  By default it stores them under \/.snapshots.  I moved it under a local user as I am not needing to use rsnapshot to backup the local backup server files.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br># SNAPSHOT ROOT DIRECTORY<br>snapshot_root \/home\/user\/rsnapshot\/snapshots\/<\/pre>\n\n\n\n<p>Add a daily backup option under Backup levels<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># BACKUP LEVELS \/ INTERVAL #<br>retain daily 6<\/pre>\n\n\n\n<p>Setup remote server to get a backup from.  Replace ipaddress and directories as needed. hostname is the sever name.  You can change to whatever you want.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">### BACKUP POINTS \/ SCRIPTS ###\n# LOCALHOST\n# Comment or delete entries unless you want to backup those as well\n# EXAMPLE.COM\nbackup  backupuser@ipaddress:\/home\/     hostname\/       +rsync_long_args=--rsync-path=\"sudo rsync\"\n<\/pre>\n\n\n\n<p>If you would like to back up multiple locations you can create multiple entries with different remote paths.  Example locations to add<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">backup  backupuser@ipaddress:\/etc\/     hostname\/       +rsync_long_args=--rsync-path=\"sudo rsync\"\nbackup  backupuser@ipaddress:\/usr\/local\/     hostname\/       +rsync_long_args=--rsync-path=\"sudo rsync\"<\/pre>\n\n\n\n<p>Verify that the config is good with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo rsnapshot configtest<\/pre>\n\n\n\n<p>It should return Syntax OK<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Crontab<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo crontab -e<\/pre>\n\n\n\n<p>Add the following line to run rsnapshot at 3AM every day.  More information about crontab can be found <a href=\"https:\/\/www.incredigeek.com\/home\/how-to-setup-a-cron-job\/\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0 3 * * * \/usr\/bin\/rsnapshot daily<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Final Testing<\/h2>\n\n\n\n<p>Manually run a backup to verify everything is set up correctly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo rsnapshot daily<\/pre>\n\n\n\n<p>After it runs you can check the directory you specified in the config file to verify that the files did get copied.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rsnapshot is a utility that uses rsync to backup files locally or it can backup files from a remote server. While trying to figure out a good solution for backing up an Ubuntu Server I decided to try rsnapshot, however &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/configure-rsnapshot-on-ubuntu-server\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,28],"tags":[75,7,1182,1184,49],"class_list":["post-3904","post","type-post","status-publish","format-standard","hentry","category-linux","category-ubuntu","tag-backup","tag-linux-2","tag-rsnapshot","tag-rsync","tag-ubuntu-2"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=3904"}],"version-history":[{"count":2,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3904\/revisions"}],"predecessor-version":[{"id":3906,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3904\/revisions\/3906"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=3904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=3904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=3904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}