Saturday, February 28, 2015

Backing-up MS Window Files to Linux on a Dual Boot Computer

Backing up files is one of those onerous tasks that has to be done if you want to preserve your data. Currently, I am running a computer using Linux (Ubuntu) with the capability to boot into MS Window 7.
I assume that many people will have a similar configuration and a need to preserve their MS Windows files. This narrative will review one approach for automatically accomplishing that task.

While most of my work is in Linux, I still have occasional need to boot into MS Windows and modify files that need to be saved. Yes, MS Windows has a backup program that can save your work. The problem, I have never gotten that backup program to function reliably. Next, my duration on MS Windows tends to be very short which circumvents the automatic scheduling of backups. Finally, the stored data is in a proprietary format and is not portable. Consequently I sought out an open source solution from the Linux environment that would accomplish and automatic backup.

As a quick aside, the back-up media that I am using is a Western Digital 2T USB hard drive that is attached to a USB port on my router. This configuration was chosen based on the premise that one should not use the same drive to backup your data. You would lose both your data and the backup should the drive fail.

When operating in Linux, there are a variety of back-up programs. Currently I am using sbackup. I have liked sbackup, but it has proven to be finicky. In this case, it appeared that sbackup was backing-up the MS Windows files. But that turned out not to be the case. The apparent "simple" solution failed. Time for Plan "B".

Plan "B" involved creating a "windows_backup" directory in my Linux home directory, using the Linux copy command, and employing anacron to schedule the backup.

The \etc\anacrontab entry to implement the backup script (program) is below.  
----------------------------------------------------------------------------------------------------------------------
 1      20      window_backup    nice  bash /home/steve/ShellScripts/windows_backup.sh
----------------------------------------------------------------------------------------------------------------------
Essentially the syntax above says to run the script (program) found in the file  "windows_backup.sh" once per-day 20 minutes after the computer boots into Linux (Ubuntu). Anacron manual page. The script below copies the MS Windows files into my Linux home directory and places them in the "windows_backup" directory. Sbackup successfully stores the files onto the Western Digital USB hard drive. No manual intervention required. Yea.
----------------------------------------------------------------------------------------------------------------------
#!/bin/bash
# Executed from /etc/anacrontab

cp -f -R -L "/media/windows/Users/Stephen/My Documents/Access" /home/steve/windows_backup/
cp -f -R -L "/media/windows/Users/Stephen/My Documents/My Garmin" /home/steve/windows_backup/
cp -f -R -L "/media/windows/Users/Stephen/My Documents/POI_Data_Files" /home/steve/windows_backup/

chown -f -R steve:backup /home/steve/windows_backup

----------------------------------------------------------------------------------------------------------------------
As a conclusionary note, sbackup is only one of many Linux based programs to backup files. I am not that familiar with the other backup programs. Please do not consider my use of sbackup as an indication that it is the backup program that is to be used. You may wish to do your own search. Other Linux based backup programs may be able to successfully copy files from an MS Windows partition without the Plan "B" option noted above.