Saturday, January 05, 2013

Backup and Restore in Ubuntu


There are various strategies for a backup depending on the method that suits your needs. Lastly the “best backup policy” will be the one that is tested and works as per your needs.

METHOD-1 (Manual)
Here we will see how to backup the data, and applications installed from the repositories of Ubuntu.

Step-1 Backup of List of All Applications
Assume if for some reason your system is not able to boot and you dont have any choice other than reinstalling the operating system. There is least possibility for anyone to remember the whole lot of packages and applications that are installed on the system. In that case there is a quick way to store a list of all installed applications and packages in a text file. This text file can be used to install all your packages automatically. This method will help you save an incrdible amount of time, especially when you need to repeat the same task multiple number of times.

So, first you have to retrieve all your installed packages to a list. You can do so by redirecting the output to a file, example – applist.txt. You need to save this file to some place so that you can use it in future for the restore process.

Follow the below mentioned steps to proceed further.
Creating backup
    1. Open the terminal and execute the below command to backup the list of your installed applications.
$ sudo dpkg –get-selections > applist.bkp
Now you can move the applist.txt file to some safe location (CD, DVD, Pendrive, etc.)

Restoring backup
You can restore your packages after a new/fresh installation of Ubuntu by moving into the folder containing your text file and follow the below mentioned steps.
$ sudo apt-get install aptitude
$ sudo dpkg –clear-selections
$ sudo dpkg –set-selections <applist.bkp>
$ sudo aptitude install
Then follow given prompts.
APTonCD, and easy GUI tool serves the same purpose.

Step-2 Backup your Data.
Most of us normally keep our data in /home. Other customizations and settings would also reside in /home. If there is some place other than /home where you keep your data, that should also be included respectively.

Step-3 Backup the System Settings.
It is a good practice to keep a copy of all system critical files like /etc/fstab, /etc/passwd, /etc/shadow, /etc/group, /etc/sudoers, /etc/hostname, and /etc/hosts. As you can see all these files are very important and are all contained in /etc, so it is more convenient to backup all of /etc directory.

Step-4 Backup Partition Table
Partition table backup proves useful in case where we need to replace a damaged hard disk and to replace the old partition table onto the new disk.
To create a copy of partition table using the below mentioned command.
$ sudo fdisk -l > fdisk.bkp
or
$ sudo sfdisk -d /dev/xyz > /<path_to_file>/sfdisk.bkp

To restore the partition table follow the below mentioned steps
$ sudo sfdisk /dev/xyz < /<path_to_file>/sfdisk.bkp
GParted Live-CD can also be very useful to backup the partition table.

Step-5 Backup your MBR
MBR is located in the first sector of hard disk and is commonly known for finding the bootable partitions in the partition table. It loads the boot sector i.e. boot loader. A damaged or corrupted MBR means that the operating system will fail to load. MBR resides in 512 byte boot sector, where 446 bytes is reserverd for bootstrap, 64 bytes for partition table and 2 bytes for signature.
MBR Backup
$ sudo dd if=/dev/xyz of=/<path_to_file>/mbr.bkp bs=512 count=1
Use “bs=446” to copy just the MBR.
Destroy MBR
To clear the MBR including the partition table use the below command. In case if you can to just kill the MBR and keep the partition table intact then simply change the value 512 to 446.
$ sudo dd if=/dev/zero of=/dev/xyz bs=512 count=1
MBR Restore
You can copy the MBR backup file to some pendrive and boot the machine using a live-CD and execute the below command to restore the old MBR.
$ sudo dd if=/<path_to_file>/mbr.bkp of=/dev/xyz bs=512 count=1
Replace xxx with the actual device name such as /dev/sda or /dev/hda. Actual device name can be found using the below command.
$ sudo sfdisk -l
Reinstallation of GRUB using the install CD in rescue mode will also give the same effect, without touching the partition table. There are many other ways to restore the MBR. There are many tools and live-CDs available to do so such as UbuntuSecureRemix, Boot-Repair-CD and TestDisk. You can google out many different ways and implement as per your convenience.

Step-6 Final backup
Finally you can also backup some additional directories like /usr/local, /opt or /usr/share, it may be anything that you have customized and put everything into an archive.
Create an archive
$ sudo tar -cvzfp backup.tar.gz /home /root /etc /<path_to_file>/mbr.bkp /<path_to_file>/sfdisk.bkp /<path_to_file>/applist.bkp
Restore archive
$ sudo tar xvzfp backup.tar.gz -C /

METHOD-2 (Using images)
Backing up data using images is very easy with the help of some tools like Partimage and Clonezilla. Even command line tools like dd, tar and rsync have proved very efficient in backups containing large data. The only disadvantage of image backups is its large size. Since it is very simple to just copy and compress the data to an image, it does backup everything on the partition. Normally everyone needs small backup containing only the data and settings on their machine, because of which this method is rarely used.

Backup tools like deja-dup, sbackup, Pybackpack and Grsync are few that are used widely for simple backup administration.

Note: Always test your backup before you implement it.

Any suggestions are more than welcome.

Tuesday, December 25, 2012

Upgrading Linux Kernel 3.7.1 (Stable) release in Ubuntu 12.10


Linux kernel 3.7.1 has recently released on December 17, 2012 with lots of bugfixes and improvements.

The changelog contains all the improvements and bugfixes made in the kernel.

Below mentioned are some important fixes and improvements.

* USB: EHCI: bugfix: urb->hcpriv should not be NULL
* ring-buffer: Fix race between integrity check and readers
    * Partial fix for a hardware bug affecting OHCI controllers by NVIDIA
    * rcu: Fix batch-limit size problem
    * usb: ftdi_sio: fixup BeagleBone A5+ quirk
    * x86: hpet: Fix masking of MSI interrupts
    * clk: ux500: fix bit error
    * rcu: Fix batch-limit size problem


We shall upgrade the default kernel version 3.5.0-17.28 shipped with Ubuntu 12.10 to 3.7.1-030701.

Download the script to perform an automated kernel upgrade process.

Now open the terminal and run the below command from the folder where script is downloaded to make it executable.
$ sudo chmod +x ker-upg-3.7.1.sh

$ sudo sh ker-upg-3.7.1.sh

After the completion, reboot the system for the changes to take effect and after reboot run the below command to confirm the version.

$ uname -r

In case if the kernel 3.7.1 is not compatible with your system hardware, then run the below command to remove the kernel 3.7.1 and switch back to previous kernel.

$ sudo apt-get purge linux-image-3.7.1-030701

Upgrading Linux Kernel 3.7.0 (Stable) release in Ubuntu 12.10


Linux kernel 3.7 has recently released on December 11, 2012 with lots of bugfixes and improvements.

The changelog contains all the improvements and bugfixes made in the kernel.

Below mentioned are some important fixes and improvements.
* ALSA: usb-audio: Fix mutex deadlock at disconnection
* ALSA: Fix card refcount unbalance
* ALSA: usb-audio: Fix races at disconnection
* DRM/Radeon: Fix Load Detection on legacy primary DAC.
* xfs: fix buffer shudown reference count mismatch
* xfs: fix reading of wrapped log data
* cfg80211: fix antenna gain handling
* drm/vmwgfx: Fix a case where the code would BUG when trying to pin GMR memory
* drm/vmwgfx: Fix hibernation device reset
* mmc: sdhci: fix NULL dereference in sdhci_request() tuning
* l2tp: fix oops in l2tp_eth_create() error path
* net: usb: Fix memory leak on Tx data path
* net: fix secpath kmemleak
* tcp: fix FIONREAD/SIOCINQ
* ipv4: Fix flushing of cached routing informations
* sctp: fix call to SCTP_CMD_PROCESS_SACK in sctp_cmd_interpreter()
* batman-adv: Fix broadcast packet CRC calculation
* NFS: fix bug in legacy DNS resolver.
* mac80211: fix SSID copy on IBSS JOIN
* drm/i915: fix overlay on i830M


We shall upgrade the default kernel version 3.5.0-17.28 shipped with Ubuntu 12.10 to 3.7.0-030700.

Download the script to perform an automated kernel upgrade process.

Now open the terminal and run the below command from the folder where script is downloaded to make it executable.
$ sudo chmod +x ker-upg-3.7.0.sh

$ sudo sh ker-upg-3.7.0.sh

After the completion, reboot the system for the changes to take effect and after reboot run the below command to confirm the version.

$ uname -r

In case if the kernel 3.7.0 is not compatible with your system hardware, then run the below command to remove the kernel 3.7.0 and switch back to previous kernel.

$ sudo apt-get purge linux-image-3.7.0-030700