What if your computer crashes tomorrow? Would you lose everything or recover in minutes?
Why Backup strategies in Linux CLI? - Purpose & Use Cases
Imagine you have hundreds of important files on your computer. You try to copy them one by one to a USB drive every week to keep them safe.
Sounds tiring, right? And what if you forget some files or miss a week?
Manually copying files is slow and easy to mess up. You might forget to copy new files or accidentally overwrite something important.
It's also hard to keep track of what was backed up and when, making recovery stressful if something goes wrong.
Backup strategies automate this process. They help you save all your important files regularly without missing anything.
With simple scripts or commands, you can schedule backups, keep multiple versions, and restore files easily when needed.
cp -r /home/user/documents /media/usb
# Repeat manually every timersync -av --delete /home/user/documents/ /media/usb/
# Run automatically with a scheduleBackup strategies let you protect your data effortlessly and recover it quickly, giving you peace of mind.
A photographer uses backup scripts to save all new photos every night to an external drive, so no precious memories are ever lost.
Manual backups are slow and risky.
Automated backup strategies save time and reduce errors.
They make data recovery simple and reliable.
Practice
Solution
Step 1: Understand what a backup is
A backup is a copy of important data saved separately to protect against loss.Step 2: Match the description to the options
Only To save copies of important files in a safe place describes saving copies in a safe place, which is the purpose of backups.Final Answer:
To save copies of important files in a safe place -> Option DQuick Check:
Backup = Save copies safely [OK]
- Confusing backup with deleting files
- Thinking backup speeds up the system
- Mixing backup with software updates
Solution
Step 1: Identify the correct option to copy directories recursively
The-roption incpcopies directories and their contents recursively.Step 2: Check other options for correctness
The plaincplacks-r, so it won't copy directories properly. The options with-dand-xuse invalid or unrelated flags.Final Answer:
cp -r /home/user/docs /backup/docs -> Option AQuick Check:
Copy directory = cp -r [OK]
- Forgetting the -r flag for directories
- Using wrong flags like -d or -x
- Assuming cp copies folders without options
rsync -av /home/user/data/ /backup/data/
Solution
Step 1: Understand rsync options -a and -v
The-aoption means archive mode (copy recursively and preserve attributes), and-vmeans verbose (show progress).Step 2: Analyze command behavior
Since /backup/data exists and is empty, rsync copies all files and folders from source to destination preserving attributes.Final Answer:
Copies all files and folders from /home/user/data to /backup/data preserving attributes -> Option BQuick Check:
rsync -av copies files with details [OK]
- Thinking rsync deletes files by default
- Confusing verbose with dry-run
- Assuming error if destination exists
#!/bin/bash cp -r /home/user/docs /backup/docs rm -r /home/user/docs/*
What is the main problem with this backup strategy?
Solution
Step 1: Analyze the script commands
The script copies /home/user/docs to /backup/docs, then deletes all files inside /home/user/docs.Step 2: Identify risk in deleting original files
Deleting original files after copying is risky if the copy failed or is incomplete, causing data loss.Final Answer:
It deletes original files after copying, risking data loss -> Option AQuick Check:
Deleting originals after backup = risk [OK]
- Assuming cp misses hidden files (it copies them)
- Thinking /backup/docs must exist (cp creates it)
- Ignoring risk of deleting original data
tar. Which command correctly creates a compressed backup file with the current date in its name?Solution
Step 1: Understand tar options for creating compressed archives
-ccreates an archive,-zcompresses with gzip, and-fspecifies the output file.Step 2: Check command correctness
tar -czf /mnt/backup/projects-$(date +%F).tar.gz /home/user/projects correctly creates a gzip compressed archive named with the current date in /mnt/backup from /home/user/projects.Final Answer:
tar -czf /mnt/backup/projects-$(date +%F).tar.gz /home/user/projects -> Option CQuick Check:
tar -czf + date = compressed dated backup [OK]
- Using -xzf which extracts instead of creates
- Swapping source and destination paths
- Omitting compression flag -z
Ready to prove it?
Pass the test and this pattern moves unknown
