Archive – Backup Linux system

Backup a complete Linux system

1. Create the following script, e.g. /usr/local/bin/backup_system.sh

#!/bin/bash
timestamp_start=`date +%s`
find / -type s -print > /tmp/sockets-to-exclude
tar cvpzf /tmp/backup.$(date +\%Y\%m\%d\%H\%M\%S).tar.gz -C / -X /tmp/sockets-to-exclude --exclude=dev --exclude=mnt --exclude=proc --exclude=sys --exclude=tmp --exclude=lost+found / > /mnt/NAS/backup.$(date +\%Y\%m\%d\%H\%M\%S).log
tar_returncode=$?
timestamp_end=`date +%s`
runtime=$((timestamp_end-timestamp_start))
echo "Backup script finished in " $runtime " seconds"
if [[ $tarreturncode -eq 1 ]]; then
        exit 0
else
        exit $tar_returncode
fi

2. Run the script and copy your /tmp/backup….tar.gz file to your final destination