7zip command-line backup

Discuss anything related to command line tools here.
Post Reply
Message
Author
User avatar
webfork
Posts: 10818
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

7zip command-line backup

#1 Post by webfork »

Background: I frequently backup a folder of important files to a Google Drive account using 7zip to both compress and encrypt it. I've been looking for a way to automate this process. I've already made the upload process a lot easier via ShareX's folder watch function but for the compression, I'm trying to speed up the sequence with standard 7-zip.

The goal here is to spend a little time on automation to save a lot of time and boring, repetitive effort over months and years. I've also more than once accidentally failed to add a password.

As many users are going to run this sort of thing on USB drives and cloud drives, I'm doing everything here with relative folders (e.g. .\output rather than z:\output)

Steps:
  1. Download and extract the 7za.exe file from 7-Zip Command Line Version site (http://7-zip.org/download.html) page and save it to the folder below the one you want to compress (in this example "FILES")
  2. Create two empty text files and save them as Compress.bat and Extract.bat
  3. Open both files and paste in the green text below:

    Compress.bat file

    Code: Select all

    7za u -mx9 -r -mhe -pSECRETCODE Backup.7z ./FILES/*
    • Explanation: This tells the computer you want to create (or update if already present) a Backup.7z file using the files in the local directory FILES and all it's subdirectories [-r] using the highest compression level [-mx9]. This will use encrypted headers (the file names are obscured) and the password "SECRETCODE" [-mhe -pSECRETCODE]
    Extract.bat file

    Code: Select all

    7za.exe x Backup.7z -o.\OUTPUT -pSECRETCODE
    • Explanation: This tells the computer you want to extract the Backup.7z file to the local folder "OUTPUT" with the same password from above
  4. Change the "SECRETCODE" to something else, ideally 15+ characters using a password generator.
  5. Launch either the Compress.bat or Extract.bat depending on your location (either beginning or destination computer)
More information / Where I Did My Research:
Other notes
  • Large backups - If you have a ton of files or a very old computer, this setup can take a lot of time. You may want to change -mx9 to -mx5 (default) or -mx2 to lower the compression level.
  • Security: This process will save the password locally to your computer. If that's an issue, you may want to run this from inside an encrypted volume like VeraCrypt or Truecrypt.
  • Compressing text files - available PPMD compression can create some dramatic space savings (http://www.dotnetperls.com/7-zip-examples)
- - -

Feedback welcome.

User avatar
webfork
Posts: 10818
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: 7zip command-line backup

#2 Post by webfork »

[Moderator note: posts about Ding-Press - 7zip front-end were given their own thread.]

Post Reply