Created
January 13, 2026 21:57
-
-
Save kubastick/94180b7d1919e622b509ab1ac5f77f3d to your computer and use it in GitHub Desktop.
Backup linux system to another disk using rsync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| BACKUP_ROOT="/mnt/backup" | |
| LOG_FILE="/var/log/rsync-backup.log" | |
| # Check if backup drive is mounted | |
| if ! mountpoint -q "$BACKUP_ROOT"; then | |
| echo "$(date): Backup drive not mounted!" | tee -a "$LOG_FILE" | |
| exit 1 | |
| fi | |
| # Perform backup | |
| echo "$(date): Starting backup..." | tee -a "$LOG_FILE" | |
| rsync -aAX --delete \ | |
| --info=progress2 \ | |
| --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/swap*","/var/cache/*","/var/tmp/*","/home/*/.cache/*"} \ | |
| / "$BACKUP_ROOT/" 2>&1 | tee -a "$LOG_FILE" | |
| if [ ${PIPESTATUS[0]} -eq 0 ]; then | |
| echo "$(date): Backup completed successfully" | tee -a "$LOG_FILE" | |
| else | |
| echo "$(date): Backup failed with errors" | tee -a "$LOG_FILE" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment