HOWTO create menu based backup and restore scripts
This guide is based on Heliode's
Howto: Backup and restore your system
http://www.ubuntuforums.org/showthread.php?t=35087
I suggest you read his guide first, then return here to create the scripts to perform his commands.
Part 1. Will explain how to create a shell script to perform the commands Heliode are explaining.
A following Part 2 (Not yet published) will consist of a more advanced and secure backup / restore system that will function over several partitions / disks, this will be published as soon as I'm finished testing it.
READ FIRST
I have successfully tested Heliod's system and have used it to restore my own system after I messed it up trying to fix the errors of the new Nvidia drivers However if you configure this wrong, or your system is set up wrong, please don't blame me. There may also may be “typos” here.. I have set up my system over several disks and therefor cannot use these scripts myself exactly how I wrote them here. I use the script which is going to be published in Part 2. I have also tested these script on other directories then “/”
First thing to do after you run the backup script the first time is to open the backup.tgz and check that all files and directories are as they should, so then you know you have a backup.
If this did'nt scare you off.. lets start looking at the scripts:
THE BACKUP SCRIPT
This is how it looks on screen:
Code:
|-------------------------------------------------------------
| IT'S RECOMMENDED TO RUN THIS SCRIPT BEFORE GNOME LOGIN
|-------------------- Press CTRL+ALT+F1 at the GDM login
|-------------------------------------------------------------
| BACKUP YOUR SYSTEM:
1) Backup
2) Exit
#?
You simply just type: sudo backup and choose with your number keys the wanted action and press Enter on the keyboard.
OK, lets start.
Open a terminal window and type:
$ gedit backup
Copy the following code into your empty text file:
Code:
#!/bin/bash
#
# A very simple backup script created by:
# Fredrik Lunde
# http://www.wine-bank.com/profile
#
# This script is related to the article:
# Howto: Backup & Restore script. Part 1
# Published at: http://ubuntuforums.org/showthread.php?p=249408
#
# Instructions:
# Change the values of "STORAGE_MEDIA" and "ROOT_EXCLUDE_DIRS"
# Name this file "restore", make it "executable" and put it in "/bin"
# Invoke by: "sudo backup"
#
# Feel free to modify however you want. If you make something better,
# please post it at the ubuntuforum.org thread above :-)
#
#------------------------------------------------------------------------------------
# CHANGE THE VALUES BELOW TO SUIT YOUR CONFIGURATION
#------------------------------------------------------------------------------------
ROOT="/*"
ROOT_EXCLUDE_DIRS="--exclude=/lost+found --exclude=/proc --exclude=/mnt --exclude=/sys --exclude=/backup.tgz"
#------------------------------------------------------------------------------------
# DO NOT CHANGE ANYTHING BELOW THIS LINE
#------------------------------------------------------------------------------------
if [ "$USER" != "root" ]; then
echo "You are not root user, use: sudo backup"
exit
fi
clear
echo "|-------------------------------------------------------------"
echo "| IT'S RECOMMENDED TO RUN THIS SCRIPT BEFORE GNOME LOGIN "
echo "|-------------------- Press CTRL+ALT+F1 at the GDM login"
echo "|-------------------------------------------------------------"
echo "| BACKUP YOUR SYSTEM: "
OPTIONS="Backup Exit"
LIST="1) Backup 2) Exit"
select opt in $OPTIONS; do
if [ "$opt" = "Exit" ]; then
clear
exit
elif [ "$opt" = "Backup" ]; then
tar cvpfz /backup.tgz $ROOT $ROOT_EXCLUDE_DIRS
echo "BACKUP COMPLETE"
exit
else
clear
echo "| BAD OPTION! Select 1 or 2"
echo "|--------------------------------------------------------------"
echo "| BACKUP YOUR SYSTEM: "
echo $LIST
fi
done
Now lets modify the script (If you have to...). By default, it makes a backup of everything in “/” so you probably don't have to change the “ROOT” configuration. Also the “ROOT_EXCLUDE_DIRS” may be left alone, but double check that it is like you want it to be according to Heliodes guide.
Save the file, exit the text editor and type in the terminal:
$ sudo chmod 775 backup
$ sudo mv backup /bin/
Now all you have todo to start the script is to type:
$ sudo backup
You can now try to open it, but exit with the option “2” and press Enter.
THE RESTORE SCRIPT
This is how it looks on screen:
Code:
|-------------------------------------------------------------
| IT'S RECOMMENDED TO RUN THIS SCRIPT BEFORE GNOME LOGIN
|-------------------- Press CTRL+ALT+F1 at the GDM login
|-------------------------------------------------------------
| RESTORE YOUR SYSTEM:
1) Restore
2) Exit
#?
Again open a terminal window and type:
$ gedit restore
Copy the following code into your empty text file:
Code:
#!/bin/bash
#
# A very simple backup restore script created by:
# Fredrik Lunde
# http://www.wine-bank.com/profile
#
# This script is related to the article:
# Howto: Backup & Restore script. Part 1
# Published at: http://ubuntuforums.org/showthread.php?p=249408
#
# Instructions:
# Change the values of "BACKUP_FILE" and "CREATE_DIRS"
# Name this file "restore", make it "executable" and put it in "/bin"
# Invoke by: "sudo restore"
#
# Feel free to modify however you want. If you make something better,
# please post it at the ubuntuforum.org thread above :-)
#
#---------------------------------------------------------------------------------
# CHANGE THE VALUES BELOW TO SUIT YOUR CONFIGURATION
#---------------------------------------------------------------------------------
BACKUP_FILE="backup.tgz"
CREATE_DIRS="/proc /sys /mnt /mnt/mounted_drive"
#---------------------------------------------------------------------------------
# DO NOT CHANGE ANYTHING BELOW THIS LINE
#---------------------------------------------------------------------------------
if [ "$USER" != "root" ]; then
echo "You are not root user, use: sudo restore"
exit
fi
clear
echo "|-------------------------------------------------------------"
echo "| IT'S RECOMMENDED TO RUN THIS SCRIPT BEFORE GNOME LOGIN "
echo "|-------------------- Press CTRL+ALT+F1 at the GDM login"
echo "|-------------------------------------------------------------"
echo "| RESTORE YOUR SYSTEM:"
tput sgr0
OPTIONS="Restore Exit"
LIST="1) Restore 2) Exit"
select opt in $OPTIONS; do
if [ "$opt" = "Exit" ]; then
clear
exit
elif [ "$opt" = "Restore" ]; then
tar xvpfz $BACKUP_FILE -C /
echo "| RESTORE COMPLETE "
if [[ -e "/proc" ]]; then
echo "$CREATE_DIRS allready exists! "
else
mkdir $CREATE_DIRS
echo "$CREATE_DIRS are created! "
fi
exit
else
clear
echo "| BAD OPTION! Select 1 or 2"
echo "|--------------------------------------------------------------"
echo "| RESTORE YOUR SYSTEM:"
echo $LIST
fi
done
Also this may need to be modified a bit. Change the value of “CREATE_DIRS” to fit your system. All you /mnt/XXX have to be put here etc.
Save the file, exit the text editor and type in the terminal:
$ sudo chmod 775 backup
$ sudo mv backup /bin/
Now all you have todo to start the script is to type:
$ sudo backup
You can now try to open it, but exit with the option “2” and press Enter.
CREATING YOUR FIRST BACKUP
Now you are ready to run your first backup. Remember to log out of gnome first.
First thing you have to do is to open the backup.tgz in the Archive Manager and check that everything is in order and that you have backed up all the files you want.
Note: If you crash your system so bad that you can't start even start console, you have to use a liveCD and use the chroot command then wake the script by sudo /bin/restore
Bookmarks