Linux Professional Institute LPIC-1 Exam 101
GNU and Unix Commands
Perform Basic File Management Part 2 archive files using tar
In this lesson, we cover two fundamental Linux backup tools:
- rsync for efficient file-level synchronization
- dd for creating bit-for-bit disk or partition images
While there are many advanced backup utilities, mastering these native commands ensures you can handle common backup and restore tasks on any Linux system.
Synchronizing Files with rsync
rsync
(remote synchronization) efficiently copies and updates files between two locations, either locally or over SSH. It transfers only changes, saving bandwidth and time.
Basic Syntax
rsync [options] [source/] [user@remote_host:/path/to/destination/]
Option | Description |
---|---|
-a | Archive mode: preserves permissions, timestamps, symlinks, recursion |
-v | Verbose output |
-h | Human-readable numbers |
-P | Show progress and keep partially transferred files |
Note
Always include a trailing slash on the source directory (source/
) to copy its contents rather than the directory itself.
Examples
Sync local → remote:
rsync -avhP Pictures/ [email protected]:/home/aaron/Pictures/
Sync remote → local:
rsync -avhP [email protected]:/home/aaron/Pictures/ Pictures/
Sync two local directories:
rsync -avh /path/to/source/ /path/to/destination/
Creating Disk Images with dd
The dd
command performs a low-level copy of a disk or partition, producing an exact image file. This is ideal for full-system backups or forensic duplication.
Warning
Before imaging, unmount the target partition or disk to prevent data corruption:
sudo umount /dev/vda1
Basic dd Command
sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress
Option | Purpose |
---|---|
if= | Input file (source disk/partition, e.g., /dev/vda ) |
of= | Output file (destination image, e.g., diskimage.raw ) |
bs= | Block size (e.g., 1M for faster transfer) |
status=progress | Display ongoing copy progress |
Sample Output
$ sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress
1340080128 bytes (1.3 GB) copied, 3 s, 432 MB/s
Restoring a Disk Image
To write the image back to a disk (this will overwrite the target):
sudo dd if=diskimage.raw of=/dev/vda bs=1M status=progress
Warning
Ensure you specify the correct of=
target. Writing to the wrong device can destroy your data.
Next Steps
Continue your journey in Linux file management:
- Explore advanced
tar
options for incremental backups - Automate backups with
cron
or systemd timers - Integrate encryption with
gpg
or LUKS for secure archives
Links and References
Watch Video
Watch video content