
{"id":13504,"date":"2022-06-14T02:43:54","date_gmt":"2022-06-14T00:43:54","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=13504"},"modified":"2025-01-23T12:05:23","modified_gmt":"2025-01-23T11:05:23","slug":"linux-server-backup-using-rclone","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/linux-server-backup-using-rclone\/","title":{"rendered":"Linux Server Backup Using Rclone"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg\" alt=\"Linux Server Backup to S3 Object Storage using Rclone\" class=\"wp-image-13612\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux-600x315.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux-768x403.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>In this post, we will show you how to create both manual and scheduled backup of any Linux server to S3 Object Storage using rclone.<\/p>\n\n\n\n<p>This guide can be used to back up any server running Linux, no matter whether it is a <a href=\"https:\/\/contabo.com\/en\/dedicated-servers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Dedicated Server<\/a>, <a href=\"https:\/\/contabo.com\/en\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS<\/a> or <a href=\"https:\/\/contabo.com\/en\/vds\/\">VDS<\/a>.&nbsp;<strong>The following commands were tested with Ubuntu 18.04(64 Bit), Ubuntu 20.04(64 Bit), Debian 9 and Debian 10. Other distributions like CentOS require a few adjustments here and there.<\/strong><\/p>\n\n\n\n<p>You need to have a root access to perform the commands listed in this article. Log in as root or elevate your rights by typing:&nbsp;<\/p>\n\n\n\n<p><code>&nbsp;sudo -i&nbsp;<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-initial-linux-server-backup-configuration-nbsp\">Initial Linux Server Backup Configuration&nbsp;<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-getting-s3-credentials-nbsp-to-store-the-backup\">1. Getting S3 Credentials&nbsp;to Store the Backup<\/h3>\n\n\n\n<p>We will be using Contabo <a href=\"https:\/\/contabo.com\/en\/object-storage\/\">Object Storage<\/a> as a backup storage in this tutorial, assuming you already have an active Object Storage subscription while following this guide.<\/p>\n\n\n\n<p>First, you need credentials such as:&nbsp;access_key, secret_key and URL. For Contabo Object Storage, these can be find in the Object Storage section of your <a href=\"https:\/\/my.contabo.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">CCP<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1249\" height=\"845\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/S3-credentials-a833c5b7e8fc8dcef9173da77583479a.png\" alt=\"\" class=\"wp-image-13509\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/S3-credentials-a833c5b7e8fc8dcef9173da77583479a.png 1249w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/S3-credentials-a833c5b7e8fc8dcef9173da77583479a-600x406.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/S3-credentials-a833c5b7e8fc8dcef9173da77583479a-768x520.png 768w\" sizes=\"auto, (max-width: 1249px) 100vw, 1249px\" \/><figcaption class=\"wp-element-caption\">S3 Object Storage credentials in CCP<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-how-to-create-a-backup-file-nbsp-on-linux-server\">2. How to Create a Backup File&nbsp;on Linux Server<\/h3>\n\n\n\n<p>First, we have to install the latest version of rclone&nbsp;<\/p>\n\n\n\n<p><code>curl https:\/\/rclone.org\/install.sh | sudo bash&nbsp;<\/code><\/p>\n\n\n\n<p>With the following command we will create a backup of the current user and stores the backup file with date in \/opt\/backup\/.<\/p>\n\n\n\n<p><code>mkdir \/opt\/backup\/&nbsp;&nbsp;<\/code><\/p>\n\n\n\n<p><code>cd \/opt\/backup &amp;&amp; tar -cvzf backup-$(date +%d.%m.%Y).tar.gz --directory=\/ --exclude=lost+found --exclude=dev\/* --exclude=proc\/* --exclude=run\/* --exclude=sys\/* --exclude=tmp\/* --exclude=mnt\/* --exclude=media\/* --exclude=opt\/backup\/* .&nbsp;<\/code><\/p>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p>Explanation of the command:&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>tar &#8211; tar creates us an archive of our data. In this example with the following parameters:&nbsp;<\/li>\n\n\n\n<li>c &#8211; (create) creates a new archive&nbsp;<\/li>\n\n\n\n<li>v &#8211; (verbose) detailed output&nbsp;<\/li>\n\n\n\n<li>&nbsp;z &#8211; (gzip) the archive will be compressed with gzip&nbsp;<\/li>\n\n\n\n<li>&nbsp;f &#8211; (file) name and location of the archive. Must be the last option passed, since everything after f is       treated as a file path.<\/li>\n\n\n\n<li>\/path\/filename.tar.gz &#8211; path to which the archive will be written.&nbsp;&nbsp;<\/li>\n\n\n\n<li>As you can see, i have excluded some of directory\u2019s we don\u2019t want to backup, because of storage space reasons or unwanted big stored files in tmp.&nbsp;<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-configuring-rclone-on-a-linux-server\">3. Configuring Rclone on a Linux Server<\/h3>\n\n\n\n<p>We assume that the files and folder you want to backup are saved in folder \/opt\/backup\/.&nbsp;<\/p>\n\n\n\n<p>Setup Rclone from our product documentation <a href=\"https:\/\/help.contabo.com\/en\/support\/solutions\/articles\/103000305592-what-is-the-rclone-tool-\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Now we are able to perform the Linux server backup with Rclone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-transferring-your-backup-nbsp-file-from-linux-server-to-s3\">4. Transferring Your Backup&nbsp;File from Linux Server to S3<mark class=\"annotation-text annotation-text-yoast\" id=\"annotation-text-85022a28-aa33-434d-a40b-1eb31a0906ba\"><\/mark><\/h3>\n\n\n\n<p>I named my object store eu2 and my backup folder backup. Now we need to create a bucket where we store all the files.<\/p>\n\n\n\n<p><code>rclone mkdir eu2:backup&nbsp;<\/code><\/p>\n\n\n\n<p>After you have completed all the steps in the &#8220;Initial Configuration&#8221; section above, run the following command to save the files to your Object Storage.<\/p>\n\n\n\n<p>All data from \/opt\/backup will transferred to your destination bucket.&nbsp;<\/p>\n\n\n\n<p><code>rclone copy -P \/opt\/backup eu2:backup\/server1&nbsp;<\/code><\/p>\n\n\n\n<p>Copy all data&nbsp;&nbsp;<\/p>\n\n\n\n<p><code>rclone move \u2013P \/opt\/backup eu2:bucketname\/server1&nbsp;<\/code><\/p>\n\n\n\n<p>Move will delete files after transfer&nbsp;<\/p>\n\n\n\n<p><code>rclone sync \u2013P \/opt\/backup eu2:bucketname\/server1&nbsp;<\/code><\/p>\n\n\n\n<p>Sync updates files on remote storage<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-scheduling-rclone-backups\">5. Scheduling Rclone Backups<\/h3>\n\n\n\n<p>After finishing the \u201cInitial Configuration\u201d section above, you can start schedule backups to be created automatically.<\/p>\n\n\n\n<p>First, we have to create the script file :<\/p>\n\n\n\n<p><code>sudo nano \/var\/rclone.sh<\/code> or a name of your choice<\/p>\n\n\n\n<p>And add this to the script :<\/p>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><code>#!\/bin\/bash<\/code><\/p>\n\n\n\n<p><code>cd \/opt\/backup &amp;&amp; tar -cvzf backup-$(date +%d.%m.%Y).tar.gz --directory=\/ --exclude=lost+found --exclude=dev\/* --exclude=proc\/* --exclude=run\/* --exclude=sys\/* --exclude=tmp\/* --exclude=mnt\/* --exclude=media\/* --exclude=opt\/backup\/* .<\/code><\/p>\n<\/div>\n<\/div>\n\n\n\n<p><code>\/usr\/bin\/rclone sync -P --update --verbose --transfers 30 --log-file=\/var\/log\/upload.log \"\/opt\/backup\" \"eu2:backup\/\"<\/code><\/p>\n\n\n\n<p>Now we make the file executable<\/p>\n\n\n\n<p><code>sudo chmod +x \/var\/rclone.sh<\/code><\/p>\n\n\n\n<p>Now we have to add our script to cron<\/p>\n\n\n\n<p><code>sudo crontab \u2013e<\/code><\/p>\n\n\n\n<p>Copy<mark class=\"annotation-text annotation-text-yoast\" id=\"annotation-text-4f509b99-8a34-46cf-a8f8-a1c532bc68e4\"><\/mark><\/p>\n\n\n\n<p><code>0 2 * * * \/var\/rclone.sh<\/code><\/p>\n\n\n\n<p>In this example, the file <code>\/var\/rclone.sh<\/code> is called every day at 02:00. You can learn more about different backup strategies in this article.<\/p>\n\n\n\n<p>You can change the time and date as you wish, if you are new to cron, you can find here a crontab generator which will helps you out.<\/p>\n\n\n\n<p>This is the easy way to keep your data complete and safe, please backup your Linux servers with a tool like rclone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-restore-data-with-rclone\">6. Restore Data with Rclone<\/h3>\n\n\n\n<p><code>rclone copy -P eu2:backup\/server1 \/opt\/backup<\/code><\/p>\n\n\n\n<p>To download your backup, you need to switch source and destination and specify which backup you actually want to download.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Additional Information\u2019s<\/strong><\/p>\n\n\n\n<p>More information&#8217;s about <a href=\"https:\/\/rclone.org\/flags\/\" rel=\"nofollow\">flags <\/a>and configuration can be found in the <a href=\"https:\/\/rclone.org\/s3\/\" rel=\"nofollow\">official documentation<\/a>.<\/p>\n\n\n\n<p><em>In some cases, you have to add \u2013s3-chunk-size 200M to your script if your upload speed is very slow.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to create a simple backup of your Linux server using rclone.<\/p>\n","protected":false},"author":56,"featured_media":13612,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[1526],"class_list":["post-13504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux-150x150.jpg",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux-600x315.jpg",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux-768x403.jpg",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/04\/blog-head_1200x630_backup-linux.jpg",1200,630,false]},"uagb_author_info":{"display_name":"Kevin","author_link":"https:\/\/contabo.com\/blog\/author\/kevink\/"},"uagb_comment_info":0,"uagb_excerpt":"How to create a simple backup of your Linux server using rclone.","authors":[{"term_id":1526,"user_id":56,"is_guest":0,"slug":"kevink","display_name":"Kevin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/6445e432ffc4b2c28a228b7ef8d536965ffc588d2bfedd5e77efab91039a5a8f?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=13504"}],"version-history":[{"count":9,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13504\/revisions"}],"predecessor-version":[{"id":21334,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13504\/revisions\/21334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/13612"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=13504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=13504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=13504"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}