Forum
Pre-upgrade, Online, Full System Backup Script - Printable Version

+- Forum (http://forum.xbian.org)
+-- Forum: Software (/forum-6.html)
+--- Forum: Others (/forum-24.html)
+--- Thread: Pre-upgrade, Online, Full System Backup Script (/thread-2413.html)



Pre-upgrade, Online, Full System Backup Script - alangibson - 3rd Aug, 2014 01:42 AM

Hello all,

After reading of problems encountered by people upgrading to new Xbian releases, I created a script that allows for point-in-time restore of an Xbian system. It basically creates an an archive of every file on your system. Since Xbian runs on Linux, it's possible to roll back the entire system just by extracting the archive.

The following script creates two scripts, /root/fullbackup.sh and /root/fullrestore.sh. It then runs /root/fullbackup.sh. When it finishes running you can upgrade with confidence knowing that you can go back to the restore point.

I recommend you run each block individually, instead of as a single script. You only have to run this script once.

Code:
# Become root
sudo su

# Make a list of paths to exclude.
# Add yours between EOFs, if needed,
cat > /root/fullbackup-excludes.txt << EOF
proc
sys
dev/pts
lost+found
root
var/cache/apt
var/lib/apt/lists
var/log
home/xbian/.xbmc/temp
media
EOF

# Create the backup script
cat > /root/fullbackup.sh << EOF
set -e
echo Making a 'clean' mount of root file system at /mnt/root
mkdir /mnt/root > /dev/null || true
mount --bind / /mnt/root
echo Running the backup chrooted to /mnt/root
chroot /mnt/root tar -cvpf /root/fullbackup.tar --directory=/ --exclude-from=/root/fullbackup-excludes.txt .
echo Unmounting the duplicate root filesystem
umount /mnt/root
EOF

# Create the restore script
cat > /root/fullrestore.sh << EOF
set -e
echo Making a 'clean' mount of root file system at /mnt/root
mkdir /mnt/root > /dev/null || true
mount --bind / /mnt/root
echo Running restore
mv /root/fullbackup.tar /fullbackup.tar
chroot /mnt/root tar -xvpf /fullbackup.tar
echo Unmounting the duplicate root filesystem
umount /mnt/root
EOF

# and make them executable
chmod 700 /root/fullbackup.sh
chmod 700 /root/fullrestore.sh

# Now run the backup
/root/fullbackup.sh

echo Backup complete. Backup file is at /root/fullbackup.tar.
echo Now you can upgrade your system. Search forum.xbian.org for instructions.
echo
echo If the upgrade succeeds, delete this backup with:
echo     sudo rm /root/fullbackup.tar
echo If it fails, roll back the entire system with:
echo     sudo /root/fullrestore.sh
echo
echo Remember: If Xbian is unable to boot, you can mount the SD card
echo in any Linux computer and do the rollback then.
echo
echo In the future, you can run the backup script directly:
echo     sudo /root/fullbackup.sh
echo
echo Good luck!

# Exit 'sudo su' so we're not root anymore
exit

If you ever want to back up again, you only need to run
Code:
sudo /root/fullbackup.sh

If the upgrade fails, roll the system back with
Code:
sudo /root/fullrestore.sh

Most of this was poached from other sites, some of which are:
http://unix.stackexchange.com/questions/98124/how-to-include-or-add-dev-with-tar-one-file-system
http://www.aboutdebian.com/tar-backup.htm


RE: Pre-upgrade, Online, Full System Backup Script - IriDium - 5th Aug, 2014 01:10 AM

Or you could just use the inbuilt btrfs snapshot and rollback function.

I also have a feeling this will not operate as you believe as btrfs is a journalled system, and sync points will be missed with your method.

Thanks for sharing.