I s pent most of my career using Unix for software development or being sys admin for a herdof Sun workstationx. Unix/Linux has many virtues.
A friend who is not technical has just switched from Windows 7 (don't laugh, he is moving his email from AOL after 36 years).. He wanted a regular backup of his files to a USB hard drive.
Okay, how hard can this be? Somewhere there is a program either GUI or shell-based that does this, right? Not that I could find. After a lot steps that brought back memories:
1. Set up mount of USB drive in /etc/mount. What? HNo atomount or autodiscovery? You run lsblk to see what devices are attached, determine which is the USB drive, copy its 8 hexadecimal digit UUID and several other close to magic fields. (I started to remember what UID and GID mean as I fiddled.)
You rediscover that mount is a very picky program. How many spaces between parameters, Running sudo mount -a may not identify errors, just silently fail. How would it be to make a mount editor that prompts you for the parameters ands adds them to /etc/mount?
3. The backup script using rsync was fairly straightforward.#!/bin/bash
# Mirror backup to USB drive (vfat friendly)
BACKUP_BASE="/mnt/usb-backup/Backups"
LOGFILE="$HOME/backup.log"
echo "$(date '+%Y-%m-%d %H:%M:%S') - Backup started" >> "$LOGFILE"
# Check if USB is mounted
if ! mount | grep -q " /mnt/usb-backup "; then
echo "$(date) - ERROR: USB not mounted at /mnt/usb-backup" >> "$LOGFILE"
echo "ERROR: Please run: sudo mount /mnt/usb-backup"
exit 1
fi
mkdir -p "$BACKUP_BASE"
# === Directories to mirror - Add more here if needed ===
declare -A DIRS=(
["/home/$(whoami)/Documents"]="$BACKUP_BASE/Documents"
["/home/$(whoami)/Pictures"]="$BACKUP_BASE/Pictures"
)
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting rsync mirror..." >> "$LOGFILE"
for src in "${!DIRS[@]}"; do
dest="${DIRS[$src]}"
if [ -d "$src" ]; then
echo "→ Mirroring $src" | tee -a "$LOGFILE"
mkdir -p "$dest"
rsync -aAX --delete --info=progress2,stats2 "$src/" "$dest/" >> "$LOGFILE" 2>&1
else
echo "Warning: $src not found" >> "$LOGFILE"
fi
done
echo "$(date '+%Y-%m-%d %H:%M:%S') - Backup completed successfully" >> "$LOGFILE"
echo "✅ Backup finished successfully!"
echo "Log saved to: $LOGFILE"
Adding an entry to crontab was simpler than mount but it still screams for a tool to help you add an entry. Some of why Linux remains user-indifferent is that for a lot of geeks it is the same theory as stick shifts: "It keeps the riff-raff out."
No comments:
Post a Comment