How to Backup a Directory in Linux
A Step-By-Step Guide for Beginners

As a fellow Linux user, I know the importance of backing up your important files and directories. After all, no one wants to lose months of hard work on a project or precious photos and documents due to hardware failure, accidental deletion, or other data loss disasters.
The good news is that Linux offers simple, built-in tools to help you regularly back up your directories.
In this beginner’s guide, I’ll walk you through the step-by-step process I use to easily back up my directories in Linux. Whether you’re protecting creative work, a website, or personal memories, effective backups are critical.
Why Should You Backup Directories in Linux?
Before we dive into the how-to, let me quickly cover why directory backups in Linux are so important:
Avoid losing files forever - Without backups, computer problems can make files totally unrecoverable. Backups let you get back missing or corrupted data.
Restore previous versions - If you make changes you later regret, backups let you “go back in time” to an earlier directory state.
Peace of mind - Once full backups are in place, you'll rest easy knowing your data is protected from all sorts of threats.
In other words, backups help us recover from our all-too-human mistakes! Now let’s get you set up.
Step 1: Install rsync
The rsync utility powers our directory backup process. Most Linux distributions have rsync built-in or easily installable from their package manager.
On Debian/Ubuntu systems, install rsync with:
sudo apt install rsync
On Fedora/CentOS/RHEL systems, use:
sudo yum install rsync
This installs rsync along with all its dependency packages. Easy enough!
Step 2: Create Your Backup Destination
Now we need to create a backup destination: somewhere to store the directory copies rsync will create.
I recommend using an external HDD or a separate internal disk partition for backups. This safeguards backups from failures of your primary disk. An external HDD kept in another location can also protect against theft, fire, or disaster.
For example, I back up important directories to a 500GB external USB hard drive. Whatever option you choose, the key requirements are:
Reliable and ideally external storage
Enough capacity to hold multiple backup versions
A simple mount point like /backup drive
If backing up across the network (not recommended for beginners), use a mount point like /network backup.
Step 3: Configure rsync
With the software installed and destination configured, it’s go time.
The basic rsync directory backup command looks like this:
rsync -av SOURCE DEST
Where SOURCE is the source directory and DEST is the backup destination path.
Some useful rsync flags to use:
-a archive mode to preserve permissions, links, etc
-v verbose to increase clarity
-z enables compression to save space
An example command would be:
rsync -avz /myphotos /backupdrive/myphotos-$(date +%F)
This will mirror the contents of /myphotos into a dated folder in /backupdrive, compressing files to conserve space.
You can back up multiple directories in a single rsync command by listing each source separated by a space.
Step 4: Automate Directory Backups
Manually running rsync each time is tedious. Luckily, we can easily automate directory backups!
Create a shell script called backup-dirs.sh to handle running rsync:
#!/bin/bash
rsync -avz /myphotos /backupdrive/myphotos-$(date +%F)
rsync -avz /documents /backupdrive/documents-$(date +%F)
Then use cron to schedule this script to run daily:
Type
crontab -eAdd this line:
0 1 * * * /backup-dirs.sh
This will now automatically back up our directories every day at 1 AM. Set a time that works for your schedule.
Consider also periodically backing up your entire system using tools like Clonezilla. Combined with regular directory backups, comprehensive system backups give you defense in depth against data loss.
You Did It! Pat Yourself on the Back
See - with just a few simple tools built into Linux, you've implemented an automated backup solution to protect your precious directories!
Going forward, periodically check that backups are succeeding as expected. Consider the 3-2-1 backup strategy for ultimate safety:
3 total copies of the data
Store backups in 2 different media types
Keep 1 backup copy off-site
Following these best practices reduces risk and minimizes data loss incidents significantly.
What questions do you have about backing up directories in Linux?
Hit reply and let me know. I'm always happy to help a fellow Linux user. And give yourself a pat on the back - great job getting backups implemented.






