The tool that I used for a long time for extracting and compressing archives is 7-Zip. It’s free, open-source, and has a powerful set of command line options that is perfect for performing backups. And today that’s exactly what we’re going to use it for.
We’re going to use a special version of 7-Zip that has no user interface whatsoever. It has to be used via the command line, and one of the benefits for using this version is that the entire application is self-contained in one single executable file. That makes it a great tool to carry around with you on a USB drive, and extremely easy to work with.
Here’s how to use the 7-Zip command line options to create backups at the click of a mouse:
- The first thing you’ll want to do is go download the command line version of 7-zip. After you extract the contents you’ll notice that there are five files available. All we need is the 7za.exe, so you can delete the rest if you wish.
- Open up Notepad, and now we’re going to create a batch file that will backup a folder location of our choosing. I’ve decided to backup everything on my desktop this time around, but it will work for any location as long as you know the path.
7za.exe a cybernet.7z "C:\Users\Ryan\Desktop"Be sure to include quotation marks around any paths that have spaces in them. For this example I didn’t have to put quotation marks around my path, but it never hurts to include them.
This will archive the documents in the 7-Zip format, which means you’ll need to have 7-Zip to extract it. It’s good because the compression ratio is very high, which means the backup file will be rather small compared to the other compression formats. If you were going to send this to someone they may have troubles opening it, but you can choose save the file as a ZIP by replacing “7z” with “zip” in that line of code.
- Now we need to save the batch file in the same place where the 7za.exe is located. In Notepad go to File -> Save As, and choose any filename. The only thing you need to make sure of is that at the end of the filename you include the .BAT extension:
- Now all you have left to do is double-click on the batch file that you just created to run it. The resulting backup file will be located in the same place as the 7za.exe and the batch file, unless you’ve specified an alternate location in Step 2.
- Extra Credit: You can always create a scheduled task that will run your batch file automatically at a time/date that you specify. That can be done by using the built-in Windows Scheduled Tasks wizard, which can be found in the Control Panel.
One other tip that I wanted to provide is how to automatically insert the current year, month, and day into the resulting filename. This would be useful for anyone looking to schedule backups, without wanting to overwrite the previous backup. In Step 2 from our example above you would want to replace:
cybernet.7z
with:
%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_cybernet.7z
which for today would give a result of:
2008-01-03_cybernet.7z
Now every backup will remain in tact, assuming that you create no more than one backup per day.
For those of you who want to dive a little deeper in to the 7-Zip command line options, here are the different things that the “a” can be replaced with in Step 2:
- a: Add to an existing archive, or create a new one
- d: Delete files from an archive
- e: Extract files from an archive
- t: Test the integrity of an archive
- u: Update the files in an archive
This is just one of the hundreds of CyberNotes we have done. You can find more of them by visiting our CyberNotes category, or by subscribing to our CyberNotes feed. We also have a full feed available if you want to receive all of our articles in your reader!
Tags: CyberNotes, Freeware, Software, Applications, Downloads, How To, Tips And Tricks


Related Posts:
- Your Week in Review with Sunday’s Summary
- “Hidden” Windows XP Command Line Programs
- CyberNotes: Assign Driver Letters to Folders in Windows
- YubNub Brings A Command Line Search Engine to Geeks
- CyberNotes: How To Create A Batch File For Synchronizing Folders





















I definitely agree - 7zip is a wonderful tool, flexible and very powerful. Thanks for the great tip, by the way! I’m recently rediscovering the utility of the command line.
Additionally, if you’re interested in a portable version that may be a little more inline with everyday use (e.g., non-command line), try 7-zip Portable, brought to you by the people over at PortableApps.com: http://portableapps.com/apps/u.....p_portable
I keep that 7-Zip portable on my Flash drive all the time. It’s a great tool to have.
Very useful, Ryan! Stumbled and del.icio.us’ed! I have been looking to automate my document backups in my laptop. Combine this with FileHamster, I can automatically move the backed up zip files to my pen drive anytime I plug that in!
TERRIFIC IDEA (Ryan and K-IntheHouse)!!
Hadn’t heard of FileHamster before, but it looks like a real gem. We’ll have to write about that.
You should take a look at Cobian Backup http://www.educ.umu.se/~cobian.....backup.htm version 9 Beta named Amanita. It now includes 7-zip compression and a great GUI for automating all your backup tasks. I have been using Cobian for years and it really is one of the best free programs I know of.
I’ll definitely have to check that app out because it looks pretty sweet.
There is a very thorough description of the command-line syntax here:
http://prudentialscatterbrain......syntax.htm
Very useful if you want to use other compression methods.