How To Back Up A Profile Folder With 7-Zip Or WinRAR From The Command Prompt

The first question people usually ask is, "If I can simply right-click and archive a profile folder, why would I bother doing it from the command line?" The answer is that if you use a scheduler, such as Windows 7′s Task Scheduler, you can’t instruct that program to right-click or click anywhere for that matter. You must give it a mouse-less way of doing what you want, and for that you need to use console commands.

WinRAR (paid) and 7-Zip (free) both have console versions that come bundled with their software, and you can use that to easily backup a profile folder elsewhere. With WinRAR there is rar.exe and unrar.exe. With 7-Zip it’s one program, 7z.exe.

For this example, a Firefox profile will be backed up.

Note before continuing: Whenever backing up a profile, it’s important that the app that uses the profile is closed, else files will be missed because they are in use by the app.

Using Windows environment variables for path locations

We use these because it’s a lot less to type. :)

Using environment variable goodness, the path to Firefox’s profiles and extensions is:

%APPDATA%\Mozilla\Firefox

The path to WinRAR is:

%PROGRAMFILES%\WinRAR\rar.exe

The path to 7-Zip is:

%PROGRAMFILES%\7-Zip\7z.exe

And the path to your desktop is:

%USERPROFILE%\Desktop

We’ll get back to these in a moment.

Diving into the Command Prompt

Once you learn how to use 7-Zip or WinRAR from the Command Prompt, it will be much easier to configure for use in the Task Scheduler app of your choice.

Open a Command Prompt window by clicking Windows Logo, typing command and selecting Command Prompt.

image

(Small side note: "Elevated permissions" are not necessary. You can run a "plain" Command Prompt; this is OK.)

For a test, we’ll create an archive of the Firefox profile folder on the desktop to make sure it works. Be sure to close Firefox first so the profile folder is freed up for backup.

Using WinRAR:

"%PROGRAMFILES%\WinRAR\rar.exe" u -r -m0 "%USERPROFILE%\Desktop\firefox-backup.rar" "%APPDATA%\Mozilla\Firefox"

…which looks like this on the command line:

image

Using 7-Zip:

"%PROGRAMFILES%\7-Zip\7z.exe" u -r -mx=0 -t7z "%USERPROFILE%\Desktop\firefox-backup.7z" "%APPDATA%\Mozilla\Firefox"

…which looks like this on the command line:

image

A detailed breakdown of each:

WinRAR: "%PROGRAMFILES%\WinRAR\rar.exe"
7-Zip: "%PROGRAMFILES%\7-Zip\7z.exe"

Launches the archive program.

WinRAR: u
7-Zip: u

Update archive. It’s most likely true you’re going to run this same command to backup your profile folder routinely, so instead of creating a new archive with "a", "u" is used instead. If no archive is present when run (which will be the case when you first run this), a new one is created.

WinRAR: -r
7-Zip: -r

Recurse subfolders. This means the archive created will include the folder and all subfolders/files under it.

WinRAR: -m0
7-Zip: -mx=0

Level of compression. You have the choice of 0 (zero) through 5. 0 is no compression and fastest. 5 is ‘ultra’ compression and slowest.

7-Zip (only): -t7z

This means "type of archive is the 7z format".

WinRAR: "%USERPROFILE%\Desktop\firefox-backup.rar"
7-Zip: "%USERPROFILE%\Desktop\firefox-backup.7z"

The destination archive you want to create. Must be surrounded in quotes.

WinRAR: "%APPDATA%\Mozilla\Firefox"
7-Zip: "%APPDATA%\Mozilla\Firefox"

The folder you want to backup. Must be surrounded in quotes.

Success?

If all went well, you have a file called firefox-backup.rar or firefox-backup.7z on your desktop depending on whether you used WinRAR or 7-Zip. Double-click to look inside the archive to make sure it backed up everything. If it did, it worked.

You can now modify the line to deliver the destination archive anywhere you wish, because it’s most likely true you don’t want it on the desktop.

Things you can do once you’re satisfied with the line

Once the command line you run archives what you want and places it where you want, you can…

Create as a quick shortcut

Right-click the desktop, create a new shortcut and paste the entire line as the location. It is not required to have this line in a batch file and will work as-is. If you routinely backup a very specific location like a profile folder, it’s actually faster to have a shortcut ready to do the job because it only requires a double-click.

Use the line in your task scheduler of choice

Any task scheduling program whether by Microsoft or not will recognize your line and run it easily at the time intervals you choose.

Important notes

For the proper backup of a profile folder, the app that uses it should not be running while the backup is taking place. If the app happens to be running, this isn’t a problem, but the archive will be missing files because the app has first priority over its own profile folder.

If you elect to use this in Windows Vista and 7′s Task Scheduler, you will have to run the task with "highest" permissions for it to work properly. The first time you run the task, it will execute normally, but the second time will fail unless you have it configured to run with highest permissions because the archive program needs it to update an existing archive.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

Discuss This Article (Without Facebook)

One comment

  1. Pretty cool. I love that you can just easily update an existing archive instead having to create a new one every time you want to back up a folder.

Leave a Reply

PCMech Insider Cover Images - Subscribe To Get Your Copies!
Learn More
Every week, hundreds of tech enthusiasts, computer owners
and geeks read The Insider, the digital magazine of PCMech.

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: