Simple Backup



This is going to explain some ideas for a really simple way to make your own backup routine.

This isn’t very fancy and in some ways it’s not the best backup solution. Let me explain what to use this for. This kind of tool can be used to “save you from yourself.” For example…. “oops I wrote over my … file”.

One solution that I’ve come up with under windows or linux is a simple batch or command script. Most computer users today have sweaty palms when they see that black screen with a little white command prompt, but it does hold great simplicity and flexibility.

Under windows. Let’s say I want to copy a file from My Documents to a folder called backups. Open up a command shell in the My Documents folder (this may be the hardest part. You may need to navigate to the My Documents folder through the command line which can be a little tricky. That might be worth another article.)

If your prompt does show that your in the right folder you can type dir to get a listing of the folder. It may be a long list, but let’s say your file is called myfile and it’s a word document, (so it’s probably really called myfile.doc). Then typing the following
copy myfile.doc backup\myfile.doc

That should put a copy of the said file in your backup directory. now this assumes you had already created that backup directory and it was in the My Documents folder. So how can we automate this? Open up notepad. No, not word, notepad. (Start, Run… notepad.) type the commands that you needed to get to the My Documents folder, then type the copy command that you used. Go to file and then save, choose ALL file types and save as mybatchfile.bat (It’s important to have ALL file types set or it will add .txt to the end which will prevent it from being run.)

Now you might save it My Documents if you like (then you won’t have to include the navigation to the My Documents folder).

Now browse to My Documents and find mybatchfile – doubleclick it. It may flash by quickly, but it may be stopped to ask a question. That’s because the copy command is usually reluctant to overwrite a file, so if your myfile.doc exists in the backup folder we need to tell it to overwrite. Open the file back up in notepad and where you have

copy myfile.doc backup\myfile.doc
add this to the end of the line /Y so that it looks like this.

copy myfile.doc backup\myfile.doc /Y

This should tell the copy command to answer Yes to the overwrite question. Save and close again and test the batch file.

You can use this with multiple files as well. The big thing to notice is this…. this will not protect your data against a hard drive failure since the backup is stored on the same drive as the original data. It might give you a safety net for when “word eats your homework..”

Under linux the commands are a bit different. Open any text editor. we’ll assume that your file is in /home/yourusername/documents. Let’s make sure the script is started out right.

Put the following in your new text document
#!/bin/bash
cd /home/yourusername/documents
cp myfile.doc ./backup/ -f

That’s it. I’ve condensed the steps here a bit since I’ve explained things a bit more for the Windows folks. For starters under linux scripts need to be told how to be interpreted. There are perl scripts/php etc. This is going to be using the bash shell and that’s what the first line sets. The second line navigates to the directory where your file is. Third line is linux’s copy command (cp) and the -f at the end “forces” the copy to take place even if the file already exists there. Of course, here again we’re assuming you’ve already created a backup folder under /home/yourusername/documents

Save and close from the file, let’s name it myscript.sh under linux the filename doesn’t have any bearing on whether or not it can be executed, I just like tagging shell scripts with the .sh ending to visually sort them. We do need to make sure we can run it though. In konqueror (if you use kde) you can navigate to where you saved the script, right click and go to properties and set it executable. Other gui’s should give you similar possibilities. Of course, you can drop to the command line and navigate to the file’s directory, then type
chmod +x myscript.sh
and press enter. then to run it you can either doubleclick it in the file browser, or type ./myscript.sh from the command line if you’re in the directory that you’ve saved it.

   Send article as PDF   

Similar Posts