Saturday, April 6, 2013

Backup/Restore Ubuntu Installation

I was sick of reinstalling all application once i installed a new version of ubuntu so i wrote these scripts to make the process easier. i hope it can help other people.

1. This script backs up the sources list and a list of installed packages to that they can be reinstalled later.

#!/bin/bash
# Save Packages List
install()
{
#install dpkg and dselect
sudo apt-get install dselect
sudo apt-get install dpkg

#save installed packages
sudo dpkg --get-selections > system
echo "Package list backup complete"

#save sources list
sudo cp /etc/apt/sources.list.d/*.list sources/
echo "Sources list backup complete"

read -p "Press [Enter] key to close"
}

cancel()
{
    echo "User cancelled package list backup"
    exit;
}

while true; do
read -p "Do you wish to save/backup the packages list from THIS computer?" yn
    case $yn in
        [Yy]* ) install; break;;
        [Nn]* ) cancel; break;;
        * ) echo "Please answer yes or no.";;
    esac
done


2. This script restores the list of sources and runs the package management tool synaptic to apply all changes.
#!/bin/bash

# Load Packages List
install()
{
#install dpkg and dselect
sudo apt-get install dselect
sudo apt-get install dpkg
sudo apt-get install synaptic

#restore PPA's
sudo cp sources/*.list /etc/apt/sources.list.d/
echo "Sources list update complete"

#show all PPA's
echo "The following PPA's are available"
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*
read -p "Press [Enter] key to continue..."

#update
sudo apt-get update

#load installed packages
    sudo synaptic -f=system 

read -p "Press [Enter] key to close"
}

cancel()
{
    echo "User cancelled package list update"
    exit;
}

while true; do
read -p "Do you wish to update/install the packages list to THIS computer?" yn
    case $yn in
        [Yy]* ) install; break;;
        [Nn]* ) cancel; break;;
        * ) echo "Please answer yes or no.";;
    esac
done





No comments:

Post a Comment