Linux System Administration for Beginners
Essential Commands
Backup files to a Remote System Optional
In this lesson, you’ll learn how to back up files on Linux using native command-line tools. We’ll cover:
- Synchronizing directories over the network with rsync
- Creating full disk or partition images with dd
These simple yet powerful utilities preserve file attributes, transfer only changed data when possible, and let you store backups remotely or locally.
Synchronize Directories with rsync
rsync
(remote synchronization) is a fast, versatile tool that copies files between local and remote directories while preserving permissions, timestamps, and symbolic links. It only transfers the differences between the source and destination, making repeated backups efficient.
Basic Syntax
rsync -a [source/] user@remote_host:[destination/]
Option | Description |
---|---|
-a | Archive mode: preserves symbolic links, permissions, timestamps, and recursion |
-v | Verbose output |
-h | Human-readable numbers |
-P | Show progress and keep partially transferred files |
Note
Adding a trailing slash to the source (e.g., ~/pics/
) copies contents of the directory. Omitting the slash (e.g., ~/pics
) copies the directory itself.
Examples
Push local directory to a remote server:
rsync -a ~/pictures/ [email protected]:/backup/pictures/
Pull a remote directory to your local system:
rsync -a [email protected]:/backup/pictures/ ~/pictures/
Synchronize two local directories:
rsync -a /path/to/source/ /path/to/destination/
On subsequent runs, only changed files are transferred, dramatically speeding up your backups.
Bit-by-Bit Backups with dd
When you need a complete disk or partition image (for cloning or disaster recovery), use dd
. It performs a raw, byte-for-byte copy.
Warning
Always unmount the target device before creating or restoring an image with dd
to avoid data corruption.
Create an Image
sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress
if=/dev/vda
Input file (source disk or partition)of=diskimage.raw
Output file (raw image)bs=1M
Block size of 1 MiB for faster transfersstatus=progress
Show live progress statistics
Restore an Image
sudo dd if=diskimage.raw of=/dev/vda bs=1M status=progress
Example output:
$ sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress
1340080128 bytes (1.3GB, 1.2GiB) copied, 3s, 432 MB/s
$ sudo dd if=diskimage.raw of=/dev/vda bs=1M status=progress
1340080128 bytes (1.3GB, 1.2GiB) copied, 3s, 432 MB/s
References
Watch Video
Watch video content