DIY Small Business PC Backup

DIY Small Business PC Backup

What do  you do if you have large files that are not irreplacable, but you just want to make sure that you can recover them in the case of a HDD crash, power outage or brownout? Back it up locally! Mind you this is NOT a replacement for encrypted online backup. In the case of a manmade or natural disaster you WILL lose your files if you do not have an offsite backup. DO NOT use this in place of an offsite backup for any important files you need for your business!!

Now that the warning’s out of the way, I’d like to share how I set up a very simple Linux bash script for my DIY Small Business PC Backup. My Ubuntu box is running on old hardware, its an old AMD K6 CPU with a gig of memory and some PATA drives I threw in it, so I can’t really reliably tell when they will decide to push daisies. I purchased an external HDD from MicroCenter and plugged the external 2.5″ HDD in to my Ubuntu samba server. Thank you to the wonderful coders at Ubuntu because it automatically mounts the drive to /media/mybook . Next I needed to write a simple bash script to compress and copy the folder I needed backed up to this external drive, and then email me that the process completed. The data is a folder that does not change often (it’s ISOs of OS discs that I use for reinstalls on customer systems if their HDD fails and they have only the CoA). 32GB of them to be precise. So, off to writing that bash script for my free DIY small business computer backup. You can use vi or your favorite linux file editor and enter the following… I will use /home/user as the source directory and /media/mybook as the target.

#!/bin/bash
### backup /home/user to /media/mybook/userbackup.tar.2bz
tar -cjf /media/mybook/userbackup.tar.bz2 /home/user

###  write email text to a temporary text file called backup.mail
echo “To: myemail@myhost.com” > backup.mail
echo “From:myemail@myhost.com” >> backup.mail
echo “Subject: My backup complete” >> backup.mail
echo “” >> backup.mail
echo “Scheduled folder backup completed at Home office” >> backup.mail

### send email from text file using msmtp
msmtp -t < backup.mail

This DIY small business pc backup script compresses 32GB of ISOs to about 30GB. So that’s about a 6% disk usage savings- not bad! Now I needed to automate my DIY small business computer backup so my computer does it instead of me having to remember to do it! Enter crontab! Crontab is like a scheduler for your system that runs all your scripts on your schedule. In this case my files do not change often so I’d like to back them up weekly.  To edit your user’s crontab file you just log in as the user you want to have run this script and enter the command “crontab -e”. That will open your editor. Inside you must update when you want the script to run and enter the path to the script. Here is an example below…

# m   h   dom  mon  dow   command
0    6     *        *          1       /myfolder/backup-script.sh

To understand the abbreviations / settings I have spaced them apart a little farther than they are in the actual file. The abbreviations stand for (from left to right) Minute, Hour, Day of Month, Month, Day of Week and Command. Since I would like my script to run every Monday at 6:00AM I entered  0 6 * * 1 and then gave the path to the script /myfolder/backup-script.sh . Now each monday morning when the backup completes, I receive an email stating that my DIY small business PC backup is done. I don’t need to worry about logging in and checking up on it in the system logs, verifying that the files are actually present in the external drive, or any silly thing like that.  It’s just automated and I don’t need to think about it just check the email and delete it. I chose to not clean up after the process because then if I don’t notice the absence of the email in my inbox for a few weeks, I can view the timestamp on that backup.mail file and see when the last time the script ran.

Leave a Reply

Your email address will not be published. Required fields are marked *