Table of Contents
A file system is an organization of data and metadata on a storage device. A filesystem contains the methods and data structures that an operating system uses to keep track of files on a disk or partition. Linux follows single hierarchal directory structure. Everything starts from the root directory, represented by /, and then expands into sub-directories. Where DOS/Windows had various partitions and then directories under those partitions, Linux places all the partitions under the root directory by mounting them under specific directories. |
||
--Linux File System Structure Explained |
One specific difference between a Linux/Unix system and Windows is the lack of drive letters. In the Windows world each hard disk partition is assigned a drive letter, typically C: thru Z: for hard disk partitions or network shares.
On a Linux system each hard disk partition is mounted to a directory on tree. One advantage to mounting is the ability to resize parts of your system by swapping in partitions. To make this clearer let me walk you through an example.
Suppose your /home partition is /dev/sda5 with a size of 10 gig but you have used 9.75 gig of space. Now lets suppose you can create a new 20 gig partition on your hard disk. You could mount the new partition on a temp location lets pick /mnt/home for /dev/sda12. Now as the root user, you can use the following commands to copy your current /home to the new partition /mnt/home.
cd /home
find . -print | cpio -pv
/mnt/home
Once the copy is finished you edit the file /etc/fstab and change the /home partition from /dev/sda5 to /dev/sda12. You can restart your system to change the mount to the new location.
You will now find you have 20 gig of space in /home.
Lets have a look at the file system as a picture.
Most of the time a Linux system will mount a memory stick automatically when you connect it to the computer. But what do you do if the system does not automatically mount a memory stick.
sudo fdisk
-l
. This will list all the disk partitions it
sees. If your hard disk is /dev/sda then you should
look for /dev/sdb partitions. Lets assume you see
/dev/sdb1 with a partition type of vfat.sudo mkdir /mnt/usbstick
.sudo mount
-v -t vfat /dev/sdb1 /mnt/usbstick
. The -v is
for verbose output, the -t is to specify the file
system type we got from fdisk.Here is a link with more details about the File System. Specifically it will explain more about Superblocks, file system types, inodes and links. This is more advanced than beginner information but is useful if you want a more detailed look. Explore Understanding UNIX / Linux File System
The first step in planning a backup is to decode how you are going to organize your restore. Now if you are confused about how to organize your restore, that is what we are going to discuss. Now there are many more ways of organizing a restore than the one I am going to propose. But if you understand how to make the decision on the restore you will be better able to decide your own strategy.
The first understanding is the different types of rescues. Let me give you a few examples.
1. You accidently deleted a file from your home folder.
This is the easiest type of recovery. All you need to do is go back to your last backup, locate the file and restore it.
2. You had a corrupted disk or you deleted a critical folder in the operating system.
You need to go back to the installation media and recover the files you need. To do this you want to follow the instructions from the operating system restore process.
3. Your hard disk failed and you lost the whole system.
Once you replace the hard disk you are going to need to reinstall the operating system, then restore your applications, and finally restore from your backup.
Before you do a backup we need to decide what we need to put on the backup media. The idea is to backup only the parts of the system which you can not restore from the install CD. The reason for a selective backup is to both save space on the backup and to make the backup faster.
The most obvious target for the backup is your home directory. But again there is no reason to backup things like the browser cache or the GUI configuration files.
Here is a list of the files and folders in my home directory on this computer
From looking at this directory listing I would backup the following directories and files.
Now my list is probably not like your list. But you get the idea of what type of files we want to backup.
Next we need to decide if there are specific files that should be included. For example the bookmark files for the three browsers I use are available in
We have two sets of files to backup. To start we need a
backup medium. For this example I will use a memory stick
formatted as vfat, located at /mnt/usbstick
and we will assume this
script is being run manually.
#!/bin/bash # Backup script of /home/john files to a memory stick at /mnt/usbstick
echo -n "Is the USB memory stick mount at /mnt/usbstick ( Y or N ): " read ANS if [ lc( $ANS ) eq "n" ] do echo Please insert the memory stick into a USB slot. Press return to continue. read ANS sudo mount -v -t vfat /dev/sdb1 /mnt/usbstick done
DATESTAMP=`date %Y%m%d`
cd /home/john tar czvf /mnt/usbstick/home-backup.${DATESTAMP}.tar.gz ./.bash \ ./Document ./Downloads ./.emacs ./house ./Music ./.ncftp \ ./Pictures ./.ssh ./transfer
# flush the buffers onto the memory stick. sync ; sync
# Unmount the USB memory stick. sudo umount -v /mnt/usbdrive
echo "You can remove the Memory stick now" exit 0
This script till mount a USB memory stick, change directory to the /home/john, then use the tar command to create an archive. Since we are including the DATASTAMP in the file name each backup will be unique unless you decide to do more than one backup in a day.
If you would like you can use the zip command instead of
the tar command by replacing tar czvf
/mnt/usbstick/home-backup.${DATESTAMP}.tar.gz
with
zip -r
/mnt/usbstick/home-backup.${DATESTAMP}.zip
both
archive programs are installed in Ubuntu.
In the past it was common to use magnetic tape to backup a hard disk. The reason was that tape was cheap and reusable. Tape can still be used but these days there are more options.
This is not intended to be a complete list but just a couple of suggestions
Back In Time is a simple backup tool for Linux inspired from “flyback project” and “TimeVault”. The backup is done by taking snapshots of a specified set of directories. |
||
--Back In Time |
Déjà Dup is a simple — yet powerful — backup tool included with Ubuntu. It offers the power of rsync with incremental backups, encryption, scheduling, and support for remote services. With Déjà Dup, you can quickly revert files to previous versions or restore missing files from a file manager window. It’s a graphical frontend to Duplicity, which itself uses rsync. It offers the power of rsync with a simple interface. |
||
--How to Back Up Ubuntu the Easy Way with Déjà Dup |
PeaZip is a free file and archive manager, based on solid and proven Open Source technology of 7-Zip for handling mainstream archive formats, and other great Open Source tools (like FreeARC, PAQ, UPX…) for supporting additional file formats and features, in order to provide an all purpose zip utility featuring a powerful unified GUI that, unlike most of other classic file archivers like i.e. WinZip and WinRar, is natively portable and cross-platform. |
||
--PeaZip Features |
Lastly I am going to leave you with a fairly recent article about online backups. Have a good read of 5 Online Backup Solutions for Ubuntu Linux as a good discussion of online backup.