-
-
Notifications
You must be signed in to change notification settings - Fork 3
Linux Backup and Restore
Complete beginner-friendly guide to backing up and restoring your Linux system, covering Arch Linux, CachyOS, and other distributions including file backups, system backups, automated backups, and restore procedures.
- Understanding Backups
- What to Backup
- File-Level Backups
- System Configuration Backups
- Full System Backups
- Automated Backups
- Restoring from Backups
- Backup Tools
- Best Practices
Backup is a copy of your data stored separately from the original.
Why backups matter:
- Data loss protection: Recover from accidental deletion
- System recovery: Restore system after failure
- Configuration recovery: Restore settings after changes
- Peace of mind: Know your data is safe
File-level backups:
- What: Backs up individual files and folders
- Use for: Documents, photos, personal files
- Tools: rsync, tar, GUI tools
System configuration backups:
- What: Backs up system settings and configuration
- Use for: Restoring system configuration
- Tools: Configuration file copying, system settings export
Full system backups:
- What: Backs up entire system
- Use for: Complete system recovery
- Tools: Timeshift, Clonezilla, dd, Btrfs snapshots
Where to store backups:
- External drive: USB drive, external hard drive
- Network storage: NAS, network drive
- Cloud storage: Online backup services
- Separate partition: Different partition on same drive
Best practices:
- Multiple locations: Don't rely on one backup
- Off-site backup: Keep copy away from computer
- Regular backups: Backup frequently
- Test restores: Verify backups work
Personal files:
- Documents, photos, videos
- Downloads folder
- Desktop files
- Music, books, etc.
Configuration files:
-
~/.config/: Application configurations -
~/.bashrc,~/.zshrc: Shell configurations -
~/.ssh/: SSH keys and configs -
~/.local/: User-specific data
System configuration:
-
/etc/: System configuration files - Package lists:
pacman -Q > package-list.txt - Bootloader configuration
Install rsync:
# Arch/CachyOS
sudo pacman -S rsync
# Debian/Ubuntu
sudo apt install rsync
# Fedora
sudo dnf install rsyncBackup home directory:
# Backup home
rsync -av --exclude='.cache' ~/ /backup/home/
# Restore
rsync -av /backup/home/ ~/Options:
-
-a: Archive mode (preserves permissions, timestamps) -
-v: Verbose output -
--exclude: Exclude directories
Create archive:
# Backup home
tar -czf backup-home-$(date +%Y%m%d).tar.gz ~/
# Backup system (exclude system directories)
sudo tar -czf backup-system.tar.gz --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run --exclude=/tmp /Restore:
# Extract
tar -xzf backup-home-20240115.tar.gz
# To specific location
tar -xzf backup-home-20240115.tar.gz -C /restore/pathBackup installed packages:
# Arch/CachyOS
pacman -Q > package-list.txt
# Debian/Ubuntu
dpkg --get-selections > package-list.txt
# Fedora
dnf list installed > package-list.txtRestore packages:
# Arch/CachyOS
pacman -S $(cat package-list.txt | cut -d' ' -f1)
# Debian/Ubuntu
dpkg --set-selections < package-list.txt
apt-get dselect-upgradeBackup config:
# Backup /etc
sudo tar -czf etc-backup.tar.gz /etc
# Backup user config
tar -czf config-backup.tar.gz ~/.configInstall Timeshift:
# Arch/CachyOS
yay -S timeshift
# Debian/Ubuntu
sudo apt install timeshift
# Fedora
sudo dnf install timeshiftCreate snapshot:
# Create snapshot
sudo timeshift --create
# List snapshots
sudo timeshift --listRestore:
# Restore from snapshot
sudo timeshift --restoreUse Clonezilla:
# Download ISO from clonezilla.org
# Boot from ISO
# Follow wizard to create disk imageCreate disk image:
# Create image
sudo dd if=/dev/sda of=/backup/system.img bs=4M status=progress
# Restore image
sudo dd if=/backup/system.img of=/dev/sda bs=4M status=progressWarning: dd can destroy data if used incorrectly. Use with caution.
If using Btrfs:
# Create snapshot
sudo btrfs subvolume snapshot / /mnt/snapshots/snapshot-$(date +%Y%m%d)
# List snapshots
sudo btrfs subvolume list /Create backup script:
# Create script
vim ~/backup.shScript example:
#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y%m%d)
# Backup home
rsync -av --exclude='.cache' ~/ "$BACKUP_DIR/home-$DATE/"
# Backup package list
pacman -Q > "$BACKUP_DIR/package-list-$DATE.txt"Make executable:
chmod +x ~/backup.shAdd to crontab:
# Edit crontab
crontab -e
# Daily backup at 2 AM
0 2 * * * /home/user/backup.shCreate service:
# Create service
sudo vim /etc/systemd/system/backup.serviceService file:
[Unit]
Description=System Backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.shCreate timer:
# Create timer
sudo vim /etc/systemd/system/backup.timerTimer file:
[Unit]
Description=Daily Backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.targetEnable timer:
sudo systemctl enable backup.timer
sudo systemctl start backup.timerFrom rsync:
rsync -av /backup/home/ ~/From tar:
tar -xzf backup-home-20240115.tar.gzFrom Timeshift:
# Boot from live USB
# Launch Timeshift
# Select snapshot
# RestoreFrom Btrfs snapshot:
# Boot from live USB
# Mount root
# Restore snapshot
sudo btrfs subvolume snapshot /mnt/snapshots/snapshot-20240115 /mnt/restoredTimeshift:
# Launch GUI
sudo timeshift-gtkDeja Dup (Debian/Ubuntu):
sudo apt install deja-dupBackInTime:
# Arch/CachyOS
yay -S backintime
# Debian/Ubuntu
sudo apt install backintime-qt43-2-1 Rule:
- 3 copies: Original + 2 backups
- 2 different media: Different storage types
- 1 off-site: Keep one backup off-site
Schedule:
- Daily: Important files
- Weekly: Full system
- Monthly: Archive old backups
Verify backups:
# Test restore to different location
# Verify files are correct
# Ensure system can bootThis guide covered backup and restore for Arch Linux, CachyOS, and other distributions, including file backups, system backups, automated backups, and restore procedures.
- System Recovery - System recovery
- Btrfs Guide - Btrfs snapshots
- Snapshots - System snapshots
- ArchWiki Backup: https://wiki.archlinux.org/title/Rsync
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.