This page shows a method that can be used to automatically mount a second hard disk to a computer running LInux. A way to create a daily backup is also included using rsync.
Mount Second Hard Drive by editing /etc/fstab
WARNING: You can seriously mess up access to your system if you ruin the fstab (Filesystem Table) file. Make sure you make a backup FIRST and know how to revert to it!
On a home system it is easy enough to edit the /etc/fstab file using gedit. You must edit this file using “root” (Admin) privilege. In Ubuntu Linux, this is done with the “sudo” command.
me@myhost$ sudo gedit /etc/fstab
I suggest you follow the suggestions in the /etc/fstab file and make your changes robust by getting a UUID number. In a separate terminal, the command for drive /dev/sda1 (see above) would be:
me@myhost$ sudo blkid /dev/sda1
Enter the data using the spacing of the lines above it. There is and explanation of the /etc/fstab file at the Fstab Wiki. In my example, the “/”, “/home”, and “swap” partitions are all on the same disk, but have different UUID numbers generated at installation. For my 2 backup disks, I manually enterd the names “/bu300” and “/bu250” after I had created these directories (folders) at the top level. This file will associate the physical disks to these mount points.
# /etc/fstab: static file system information.
#[PARTIAL FILE: Columns are as follows: File System Name, Mount Point, Filesystem Type, Options, Dump, and Pass*.
# / was on /dev/sda1 during installation
UUID=71537a2a-2c85-40b1-9969-6b73ead86456 / ext4 errors=remount-ro 0 1
# /home was on /dev/sda3 during installation
UUID=edbed3cc-dd0a-404c-898e-551eb41a1bb3 /home ext4 defaults 0 2
# swap was on /dev/sda5 during installation
UUID=99e91184-e43b-4889-8bfb-ae86017ed5ec none swap sw 0 0
# Two backup drives 300GB and 250GB. Get UUID with "blkid" command.
UUID=ab5830c2-6591-48f9-854e-ee702ccdda5b /bu300 ext4 defaults 0 2
UUID=43ff7d13-ece5-4459-9a0c-8421d86d51a0 /bu250 ext4 defaults 0 2
That’s it!. After you restart your computer, the drives will be automatically mounted at the “mount points” listed in the /etc/fstab file.
Create & Run A Backup Script Using rsync
Give yourself permissions if necessary on your /backup drive:
me@myhost$ sudo chown -R USER_NAME /backup
me@myhost$ sudo chgrp -R USER_NAME /backup
The program rsync efficiently synchronizes two folders by only modifying the files in the final directory that have changed since the last synchronization. The -av options DO NOT delete files, though, they only update changed files and add new ones. You need to eventually “clean up” the /backup folder of stuff you REALLY want to delete.
Below is an sample backup script that matches the default files in a Ubuntu Linux installation. In this example the only mount point created was /backup for a single backup hard drive. You need to substitute your user name for USER_NAME.
rsync -av /home/USER_NAME/Documents/ /backup/Documents
rsync -av /home/USER_NAME/Downloads/ /backup/Downloads
rsync -av /home/USER_NAME/Music/ /backup/Music
rsync -av /home/USER_NAME/Pictures/ /backup/Pictures
rsync -av /home/USER_NAME/Public/ /backup/Public
rsync -av /home/USER_NAME/Videos/ /backup/Videos
Scheduling a “cron job” is something more suited to a server that is operating 24×7. An alternative to get regular backups is to add a item to the program Startup Applications. If you named your backup script above “backup.sh” in your home directory, then the “Command” box item would be “/home/USER_NAME/backup.sh”, or “./backup.sh”. For a home-based system that gets turned off regularly, this will cause your files to be backed up every time you turn the comptuer on, and it won’t rely on the computer being on at “X o-clock”. It is probably a better option for me.