{"id":9304,"date":"2025-01-20T02:00:00","date_gmt":"2025-01-20T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=9304"},"modified":"2025-01-20T09:48:55","modified_gmt":"2025-01-20T14:48:55","slug":"personal-backups-with-rsync","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=9304","title":{"rendered":"Personal backups with \u2018rsync\u2019"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"9304\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>Our data is our digital lives. If we lose our data, we lose more than just a few files\u2014personal data can include photos, resumes, and hobby projects. If your primary computer is a laptop, consider that you take your personal data with you <em>everywhere<\/em>, and you can lose all of that if your laptop is stolen, lost, or damaged.<\/p>\n\n\n\n<p>At a minimum, you need good backups. Don\u2019t overthink your backup strategy: just making a copy of your files to a USB flash drive once a week, and putting that drive in a drawer, can save you if you lose your data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"making-backups-with-rsync\">Making backups with \u2018rsync\u2019<\/h2>\n\n\n\n<p>An easy and reliable way to make a backup is to \u201cdrag and drop\u201d files and folders in the file manager to <em>copy<\/em> your data to the second drive. But this method may not preserve all of the attributes of your files. If you want to keep permissions and file creation dates, you need a different method. That\u2019s where the <strong>rsync<\/strong> command comes in.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.both.org\/?p=4647\" target=\"_blank\" rel=\"noreferrer noopener\">The <strong>rsync<\/strong> command<\/a> was originally invented to synchronize files between two <em>remote<\/em> systems. That\u2019s where the name came from: <strong>r<\/strong>emotely <strong>sync<\/strong>hronize between systems. But you can just as easily use <strong>rsync<\/strong> to synchronize files between two directories: your home directory and a \u201cbackup\u201d directory.<\/p>\n\n\n\n<p>Making a backup with <strong>rsync<\/strong> is just a two-step process: prepare the backup directory, and run the backup with <strong>rsync<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"set-the-backup-directory\">1. Prepare the backup directory<\/h3>\n\n\n\n<p>Start by plugging in a USB flash drive to your Linux system. Your file manager should automatically recognize it and make it available for use (a process called \u201cmounting\u201d). The default \u201cmount\u201d location is under the <code>\/run\/media<\/code> path, plus your username, then the name of the drive. For example, my backup drive gets mounted as <code>\/run\/media\/jhall\/Backup<\/code>.<\/p>\n\n\n\n<p>Open a terminal window, and make a new directory on the drive to make your backups. I like to use the date for my backup directory, such as this command to make a backup on January 15:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mkdir \/run\/media\/jhall\/Backup\/2025-01-15<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"run-the-backup\">2. Run the backup<\/h3>\n\n\n\n<p>Now you\u2019re ready to make a backup of your files with the <strong>rsync<\/strong> command. To make a backup, you just need one option: <strong>-a<\/strong> will use \u201carchive mode,\u201d but you can think of this option as \u201call\u201d because it saves everything. Using <strong>-a<\/strong> means the backup runs <em>recursively<\/em> (same as <strong>-r<\/strong>) and saves links as links (same as <strong>-l<\/strong>) and preserves all permissions (same as <strong>-p<\/strong>). It also keeps timestamps (same as <strong>-t<\/strong>) and group and owner permissions (same as <strong>-g<\/strong> and <strong>-o<\/strong>) and any special device information (same as <strong>-D<\/strong>). You don\u2019t have to specify the <strong>-r -l -p -t -g -o -D<\/strong> options, using <strong>-a<\/strong> does all of that for you. To make the backup, type this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rsync -a $HOME\/ \/run\/media\/jhall\/Backup\/2025-01-15\/<\/code><\/pre>\n\n\n\n<p>If the directory name ends with a slash, <strong>rsync<\/strong> will recognize it as a directory and copy everything in it.<\/p>\n\n\n\n<p>How long this backup takes will depend on how much data it needs to copy and the speed of the backup device. My backups take about ten minutes. After you make the backup, use your file manager to safely remove the flash drive from the system. Most file managers will have an \u201ceject\u201d icon next to a removeable drive; clicking this will tell the system to stop using the drive (called \u201cunmounting\u201d).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"personal-backups-with-rsync\">Personal backups with \u2018rsync\u2019<\/h2>\n\n\n\n<p>By making backups using <strong>rsync<\/strong>, your files are <em>copied<\/em> to the destination, preserving all permissions. You don&#8217;t have to go through a complicated process or run other commands to restore your data in case of a loss. You can simply copy the files and folders you need. That makes it easy to restore just a few files at a time, in case you accidentally delete or overwrite one or two important files by accident. Just navigate to those files on the backup drive, and copy them back to your home directory.<\/p>\n\n\n\n<p>My Linux home directory is about 19GB, which I can easily fit on a 32GB USB flash drive, although for not much more, you can buy a 128GB USB flash drive for about $20 or $25. I recommend you get two of them so you always have a second copy of your data. For less than $50 total, you can safely protect your data from total loss.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make backups of your personal data in case your laptop is lost, stolen, or damaged.<\/p>\n","protected":false},"author":33,"featured_media":2818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[346,5],"tags":[347,91],"class_list":["post-9304","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backups","category-linux","tag-backups","tag-linux"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9304"}],"version-history":[{"count":5,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9304\/revisions"}],"predecessor-version":[{"id":9335,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9304\/revisions\/9335"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/2818"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}