[Guide] Universal & Automated System Backup and Restore for Zorin OS Lite
This guide explains how to set up a 100% universal, automated, and lightweight backup and restore system for Zorin OS 18 Lite (XFCE). It backs up your standard software (APT), external software (PPAs/third-party repositories), Flatpak applications, and your XFCE desktop layout.
This system uses environment variables, meaning it works out-of-the-box on any computer and for any user without modifying the code. It is configured to run automatically every Friday at 6:00 PM and will intelligently keep only the 3 most recent backups to save disk space.
⚠️ Security & Stability Note
- Safe Architecture: This script uses a "declarative" approach. It does not clone vital system files or the Linux kernel, making it inherently safe. A failed restore will never prevent your PC from booting.
- No Password Storage: The script never saves your
sudopassword. The automated backup runs safely within your user space, and the restore script will securely prompt you for your password in real-time when system privileges are required. - Repository Integrity: The script copies your existing
/etc/apt/sources.list.dconfiguration. It does not introduce new vulnerabilities, but it will restore whatever repositories you currently have. Ensure your current system repositories are trusted before running it. - Resilient Restorations: The official Zorin OS package manager (
apt/dpkg) handles the reinstallation process. If a software package becomes obsolete, changes its URL, or is no longer available, the system will simply skip it and move to the next item without crashing or freezing your machine.
Step 1: Create the Universal Scripts via Terminal
Open your Terminal (Ctrl + Alt + T), copy-paste the following command block to create the Ultimate Backup Script, and press Enter:
cat << 'EOF' > ~/sauvegarde_auto.sh
#!/bin/bash
DOSSIER_PARENT="$HOME/Sauvegardes_Systeme"
DOSSIER_SAUVEGARDE="$DOSSIER_PARENT/Point_$(date +%Y-%m-%d_%Hh%M)"
mkdir -p "$DOSSIER_PARENT"
echo "1. Creating complete restoration point..."
mkdir -p "$DOSSIER_SAUVEGARDE"
# A. Backup external repositories (PPAs)
echo "-> Backing up sources and external repositories..."
cp -r /etc/apt/sources.list.d "$DOSSIER_SAUVEGARDE/sources.list.d"
cp -r /etc/apt/trusted.gpg.d "$DOSSIER_SAUVEGARDE/trusted.gpg.d" 2>/dev/null
if [ -f /etc/apt/trusted.gpg ]; then
cp /etc/apt/trusted.gpg "$DOSSIER_SAUVEGARDE/trusted.gpg"
fi
# B. Backup software lists (APT & Flatpak)
echo "-> Backing up applications lists..."
dpkg --get-selections > "$DOSSIER_SAUVEGARDE/liste_paquets.txt"
if command -v flatpak &> /dev/null; then
flatpak list --columns=application > "$DOSSIER_SAUVEGARDE/liste_flatpak.txt"
fi
# C. Backup visual configuration (XFCE)
echo "-> Backing up desktop environment layout..."
tar -czf "$DOSSIER_SAUVEGARDE/config_xfce.tar.gz" -C "$HOME" .config/xfce4 .config/dconf 2>/dev/null
echo "Backup successful!"
echo "------------------------------------------------"
# D. Smart cleaning (Keeps only the 3 most recent backups)
echo "2. Intelligent cleanup..."
cd "$DOSSIER_PARENT" || exit
ls -dt Point_* 2>/dev/null | tail -n +4 | while read -r dossier_ancien; do
echo "Deleting older backup: $dossier_ancien"
rm -rf "$dossier_ancien"
done
echo "------------------------------------------------"
echo "Operation completed successfully!"
EOF
Next, copy-paste this second block into the Terminal to create the Ultimate Restore Script, and press Enter:
cat << 'EOF' > ~/restaurer_systeme.sh
#!/bin/bash
DOSSIER_PARENT="$HOME/Sauvegardes_Systeme"
DERNIERE_SAUVEGARDE=$(ls -dt "$DOSSIER_PARENT"/Point_* 2>/dev/null | head -n 1)
if [ -z "$DERNIERE_SAUVEGARDE" ]; then
echo "❌ Error: No backup found in $DOSSIER_PARENT"
exit 1
fi
echo "===================================================="
echo "🔄 SYSTEM RESTORATION (UNIVERSAL MODE)"
echo "Detected backup: $DERNIERE_SAUVEGARDE"
echo "===================================================="
read -p "Do you want to launch the full restoration? (y/n) : " CONFIRM
if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then
echo "Operation cancelled."
exit 0
fi
# A. Restore PPAs
echo "⏳ Restoring third-party software repositories..."
if [ -d "$DERNIERE_SAUVEGARDE/sources.list.d" ]; then
sudo cp -r "$DERNIERE_SAUVEGARDE/sources.list.d/"* /etc/apt/sources.list.d/
sudo cp -r "$DERNIERE_SAUVEGARDE/trusted.gpg.d/"* /etc/apt/trusted.gpg.d/ 2>/dev/null
if [ -f "$DERNIERE_SAUVEGARDE/trusted.gpg" ]; then
sudo cp "$DERNIERE_SAUVEGARDE/trusted.gpg" /etc/apt/trusted.gpg
fi
sudo apt update
echo "✅ External repositories restored."
fi
# B. Restore Desktop layout
echo "⏳ Restoring visual configurations..."
if [ -f "$DERNIERE_SAUVEGARDE/config_xfce.tar.gz" ]; then
tar -xzf "$DERNIERE_SAUVEGARDE/config_xfce.tar.gz" -C "$HOME"
echo "✅ XFCE and Dconf configurations restored."
fi
# C. Reinstall standard packages (APT)
echo "⏳ Downloading and reinstalling standard software..."
if [ -f "$DERNIERE_SAUVEGARDE/liste_paquets.txt" ]; then
sudo dpkg --clear-selections
sudo dpkg --set-selections < "$DERNIERE_SAUVEGARDE/liste_paquets.txt"
sudo apt-get dselect-upgrade -y
echo "✅ System software restored."
fi
# D. Reinstall Flatpaks
echo "⏳ Reinstalling Flatpak applications..."
if [ -f "$DERNIERE_SAUVEGARDE/liste_flatpak.txt" ] && command -v flatpak &> /dev/null; then
while read -r application; do
if [ ! -z "$application" ]; then
flatpak install flathub "$application" -y --noninteractive
fi
done < "$DERNIERE_SAUVEGARDE/liste_flatpak.txt"
echo "✅ Flatpak applications restored."
fi
echo "===================================================="
echo "🎉 Restoration completed successfully!"
echo "Please restart your PC."
echo "===================================================="
EOF
Step 2: Make the Scripts Executable
To grant permission to execute these scripts, run the following command:
chmod +x ~/sauvegarde_auto.sh ~/restaurer_systeme.sh
Step 3: Enable Automatic Scheduling (Every Friday at 6:00 PM)
Inject the scheduled task directly into your cron system with this single command line (no text editor required):
(crontab -l 2>/dev/null; echo "0 18 * * 5 /bin/bash \$HOME/sauvegarde_auto.sh >/dev/null 2>&1") | crontab -
Step 4: Create Desktop Launchers (Buttons)
To run these actions easily from your desktop without typing commands, generate two clickable icons on your desktop with this command block:
# 1. Create Backup Button
cat << 'EOF' > ~/Desktop/Create_Backup.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Create System Backup
Comment=Launches an immediate manual backup
Exec=xfce4-terminal -e "bash -c '$HOME/sauvegarde_auto.sh; echo; read -p \"Press Enter to close...\"'"
Icon=document-save
Terminal=false
Categories=System;
EOF
# 2. Emergency Restore Button
cat << 'EOF' > ~/Desktop/Restore_System.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Restore System
Comment=Launches the emergency restoration script
Exec=xfce4-terminal -e "bash -c '$HOME/restaurer_systeme.sh; exec bash'"
Icon=system-software-update
Terminal=false
Categories=System;
EOF
# Authorize both desktop buttons
chmod +x ~/Desktop/Create_Backup.desktop ~/Desktop/Restore_System.desktop
Note: The first time you double-click one of these desktop icons, Zorin OS Lite will prompt a security pop-up. Click "Mark Executable" to activate it permanently.
*AI-assisted tutorial, please verify critical steps*