I’ve recently completed building a file server for my home. The purpose of the machine is to provide storage space for precious memories and projects. I built a Linux machine instead of buying a ready made NAS because I wanted something that was more configurable and cost effective.  If you look at NAS devices that are meant for home or small business users they have many limitations that simply aren’t present with a full Linux based PC. Hard drive sizes, memory upgrades, choice of NIC or adding WiFi are all things that I have free choice about and can change at will during or after the build when I build it myself. Then there’s cost. Using off the shelf parts that are a year to two years old on the technology scale allow me to save hundreds of $$$.

This article will show one more benefit. The ability to decide what happens on my server and when in regards to hard drive configuration and backups.

My server is configured with 4 hard drives at this time. Two provide for the operating system, programs and backup for the home folder. The other two are the main storage for the network. These drives need to be mirrored. Because I used Ubuntu Linux there is no reason to purchase a hardware solution for mirroring of drives. I can simply use a program called rsync. I wrote a very simple script for rsync and set that in my home directory. I then edited the crontab to fire that script every day. This provides a complete mirror that will only copy over the new files, which is exactly what I want.

Here is the rsync script that I built:

#!/bin/bash
################################################
#
# Copy all media files to 2nd drive
#
################################################

# What to copy
copy_files=”/media/data00/documents /media/data00/magazines /media/data00/movies /media/data00/music /media/data00/pictures /media/data00/tv /media/data00/video”

# Where to copy to
dest=”/media/data01″

# Use rsync to do direct file copy
rsync -av $copy_files $dest

My drives are named data00 and data01, the folders to be copied are the only folders on the primary data drive. The switches for rsync handle archiving and verbose mode so that I can watch what happens the first time the script runs. Like I said, this is a very simple script.

Next I modified the crontab file to run once per day. Use this command in terminal if you wish to run as root:

sudo crontab -e

Then I added this line so that the script that I made will run once per day:

0 0 * * * bash /home/kevin/Documents/backup_now.sh

If you were to do something similar you would only have to change the name and location of your script file.

Share