CachyOS Backup and Restore - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
CachyOS Backup and Restore Guide
Complete beginner-friendly guide to backing up and restoring your CachyOS system, including files, system configuration, and full system backups.
Table of Contents
- Understanding Backups
- What to Backup
- File-Level Backups
- System Configuration Backups
- Full System Backups
- Automated Backups
- Restoring from Backups
- Backup Best Practices
Understanding Backups
What is a Backup?
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
Types of Backups
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
Backup Storage Locations
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
What to Backup
Essential Files to Backup
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/home/: User home directories- Package lists: Installed packages
What NOT to Backup
Don't backup:
/proc/: Virtual filesystem (runtime data)/sys/: Virtual filesystem (kernel data)/dev/: Device files (created automatically)/tmp/: Temporary files/run/: Runtime data- Cache directories: Can be regenerated
Why:
- These are system-generated
- Can cause issues if restored
- Not needed for recovery
File-Level Backups
Using rsync
rsync is a powerful file synchronization tool.
Install rsync:
sudo pacman -S rsync
Basic backup:
rsync -av /source/directory/ /destination/directory/
What this does:
-a: Archive mode (preserves permissions, timestamps)-v: Verbose (shows what's being copied)- Copies files from source to destination
Example:
rsync -av ~/Documents/ /media/backup/Documents/
What this does:
- Backs up Documents folder
- Preserves file attributes
- Shows progress
Exclude files:
rsync -av --exclude '*.tmp' /source/ /destination/
What this does:
- Excludes files matching pattern
*.tmp: Excludes temporary files- Useful for skipping cache, temp files
Dry run (test without copying):
rsync -av --dry-run /source/ /destination/
What this does:
- Shows what would be copied
- Doesn't actually copy
- Useful for testing
Using tar
tar creates archive files.
Create backup archive:
tar -czf backup.tar.gz /path/to/backup/
What this does:
-c: Create archive-z: Compress with gzip-f: Archive filename- Creates compressed backup file
Example:
tar -czf ~/backup-home.tar.gz ~/
What this does:
- Creates backup of home directory
- Compresses with gzip
- Saves to home directory
Extract archive:
tar -xzf backup.tar.gz
What this does:
-x: Extract archive-z: Decompress gzip-f: Archive filename- Extracts files from backup
List archive contents:
tar -tzf backup.tar.gz
What this does:
-t: List contents- Shows files in archive
- Doesn't extract
GUI Backup Tools
BackInTime:
sudo pacman -S backintime
What it does:
- Graphical backup tool
- Easy to use
- Automatic backups
Timeshift (file mode):
sudo pacman -S timeshift
What it does:
- System restore tool
- Can backup files
- Easy GUI
System Configuration Backups
Backing Up Configuration Files
Backup user config:
tar -czf ~/config-backup.tar.gz ~/.config/
What this does:
- Backs up configuration directory
- Preserves all settings
- Easy to restore
Backup system config:
sudo tar -czf ~/etc-backup.tar.gz /etc/
What this does:
- Backs up system configuration
- Requires sudo (system files)
- Important for system recovery
Backup shell config:
cp ~/.bashrc ~/.bashrc.backup
cp ~/.zshrc ~/.zshrc.backup
What this does:
- Backs up shell configuration
- Simple copy
- Easy to restore
Backing Up Package Lists
Export installed packages:
pacman -Qqe > ~/installed-packages.txt
What this does:
- Lists all explicitly installed packages
- Saves to text file
- Useful for reinstalling
Export with AUR packages:
pacman -Qqem > ~/all-packages.txt
What this does:
- Lists all packages (including AUR)
- More comprehensive list
- Includes AUR packages
Restore packages:
# From official repos
pacman -S --needed $(cat ~/installed-packages.txt)
# From AUR (if using yay)
yay -S --needed $(cat ~/all-packages.txt | grep -v "$(pacman -Qqm)")
What this does:
- Reads package list
- Installs packages
--needed: Skips already installed
Backing Up Desktop Environment Settings
KDE Plasma:
# Backup KDE settings
tar -czf ~/kde-settings.tar.gz ~/.config/plasma* ~/.kde/
GNOME:
# Backup GNOME settings
dconf dump / > ~/gnome-settings-backup.txt
What this does:
- Exports GNOME settings
- Saves to text file
- Can be restored with
dconf load
Full System Backups
Using Timeshift
Timeshift is a system restore tool.
Install Timeshift:
sudo pacman -S timeshift
Launch Timeshift:
sudo timeshift-gtk
What it does:
- Creates system snapshots
- Can restore entire system
- Easy GUI interface
Create snapshot:
- Open Timeshift
- Click "Create"
- Choose snapshot type
- Wait for completion
Restore snapshot:
- Open Timeshift
- Select snapshot
- Click "Restore"
- Follow prompts
** Warning**: Restoring will replace current system!
Using Clonezilla
Clonezilla creates disk images.
Install Clonezilla:
sudo pacman -S clonezilla
Or use live USB:
- Download Clonezilla ISO
- Create bootable USB
- Boot from USB
Create disk image:
- Boot Clonezilla
- Select "device-image"
- Choose source disk
- Choose destination
- Start cloning
Restore disk image:
- Boot Clonezilla
- Select saved image
- Choose target disk
- Start restore
** Warning**: Will overwrite target disk!
Using dd
dd is a low-level disk copying tool.
** Warning**: dd is powerful but dangerous! Use carefully.
Create disk image:
sudo dd if=/dev/sda of=/path/to/backup.img bs=4M status=progress
What this does:
if=/dev/sda: Input file (source disk)of=: Output file (backup image)bs=4M: Block size (4MB)status=progress: Show progress
Restore disk image:
sudo dd if=/path/to/backup.img of=/dev/sda bs=4M status=progress
What this does:
- Restores from image
- Overwrites target disk
- ** Destructive operation!**
** Double-check device names!** Wrong device = data loss!
Automated Backups
Using cron
cron schedules tasks automatically.
Edit crontab:
crontab -e
Add backup job:
0 2 * * * rsync -av ~/Documents/ /media/backup/Documents/
What this does:
- Runs at 2:00 AM daily
- Backs up Documents folder
- Automatic backup
Cron syntax:
minute hour day month weekday command
Examples:
0 2 * * *: Daily at 2:00 AM0 */6 * * *: Every 6 hours0 0 * * 0: Weekly on Sunday
Using systemd timers
Create timer unit:
sudo nano /etc/systemd/system/backup.timer
Add:
[Unit]
Description=Daily backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
Create service unit:
sudo nano /etc/systemd/system/backup.service
Add:
[Unit]
Description=Backup service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup-script.sh
Enable timer:
sudo systemctl enable --now backup.timer
What this does:
- Creates scheduled backup
- Runs daily automatically
- More reliable than cron
Backup Scripts
Create backup script:
nano ~/backup.sh
Add:
#!/bin/bash
BACKUP_DIR="/media/backup"
DATE=$(date +%Y-%m-%d)
# Create backup directory
mkdir -p "$BACKUP_DIR/$DATE"
# Backup home directory
rsync -av --exclude '*.cache' ~/ "$BACKUP_DIR/$DATE/home/"
# Backup system config
sudo tar -czf "$BACKUP_DIR/$DATE/etc-backup.tar.gz" /etc/
echo "Backup completed: $DATE"
Make executable:
chmod +x ~/backup.sh
Run manually:
~/backup.sh
Or schedule with cron/systemd
Restoring from Backups
Restoring Files
From rsync backup:
rsync -av /backup/location/ ~/restored/
What this does:
- Restores files from backup
- Preserves attributes
- Copies to destination
From tar archive:
tar -xzf backup.tar.gz -C ~/restored/
What this does:
- Extracts archive
-C: Extract to directory- Restores files
Restoring Configuration
Restore user config:
tar -xzf ~/config-backup.tar.gz -C ~/
What this does:
- Restores configuration files
- Overwrites existing config
- ** May overwrite current settings**
Restore system config:
sudo tar -xzf ~/etc-backup.tar.gz -C /
What this does:
- Restores system configuration
- Requires sudo
- ** May affect system**
Restore GNOME settings:
dconf load / < ~/gnome-settings-backup.txt
What this does:
- Restores GNOME settings
- Loads from backup file
- Applies immediately
Restoring System
Using Timeshift:
- Boot from live USB if needed
- Open Timeshift
- Select snapshot
- Click "Restore"
- Follow prompts
Using Clonezilla:
- Boot Clonezilla
- Select image
- Choose target
- Start restore
** Warning**: System restore will replace current system!
Backup Best Practices
Regular Backups
Schedule:
- Daily: Important files
- Weekly: Full system
- Before changes: Before major updates/changes
Automate:
- Use cron or systemd timers
- Set up automatic backups
- Don't rely on manual backups
Multiple Backups
3-2-1 Rule:
- 3 copies: Original + 2 backups
- 2 different media: Different storage types
- 1 off-site: Backup away from computer
Why:
- Redundancy protects against failure
- Different media = different failure modes
- Off-site = protection against disasters
Test Restores
Regular testing:
- Test restore process
- Verify backups work
- Don't wait for disaster
How to test:
- Restore to test location
- Verify files are correct
- Check file integrity
Backup Verification
Verify backups:
# Check file integrity
md5sum backup.tar.gz > backup.md5
md5sum -c backup.md5
What this does:
- Creates checksum
- Verifies file integrity
- Detects corruption
Regular verification:
- Check backups periodically
- Verify they're not corrupted
- Ensure they're accessible
Backup Security
Encrypt backups:
# Encrypt backup
tar -czf - ~/Documents/ | gpg -c > backup.tar.gz.gpg
What this does:
- Encrypts backup with GPG
- Requires password to decrypt
- Protects sensitive data
Decrypt backup:
gpg -d backup.tar.gz.gpg | tar -xzf -
What this does:
- Decrypts backup
- Extracts files
- Requires password
Additional Resources
- CachyOS Post-Installation Guide - System setup
- Arch Linux Wiki - Rsync: https://wiki.archlinux.org/title/Rsync
- Timeshift Documentation: https://github.com/teejee2008/timeshift
- Clonezilla Documentation: https://clonezilla.org/
Summary
This guide covered:
- Understanding backups - What backups are and why they matter
- What to backup - Essential files and configurations
- File-level backups - Using rsync, tar, GUI tools
- System configuration backups - Config files, package lists
- Full system backups - Timeshift, Clonezilla, dd
- Automated backups - cron, systemd timers, scripts
- Restoring from backups - How to restore files and system
- Best practices - Regular backups, testing, security
Key Takeaways:
- Backup regularly and automatically
- Use multiple backup locations
- Test restore process
- Verify backup integrity
- Encrypt sensitive backups
- Follow 3-2-1 rule (3 copies, 2 media, 1 off-site)
- Backup before major changes
- Keep backups organized and labeled
This guide is based on the CachyOS Wiki and Arch Linux Wiki and expanded with detailed explanations for beginners. For the most up-to-date backup information, always refer to the official documentation.