Automate Daily Backups with 7-Zip and Task Scheduler

This article provides a step-by-step guide on how to automatically create daily, timestamped ZIP archives of your important files using the free 7-Zip utility and the built-in Windows Task Scheduler. By combining a lightweight batch script with scheduled automation, you can establish a reliable, zero-cost backup system that runs seamlessly in the background without requiring manual intervention.

Step 1: Verify the 7-Zip Installation Path

7-Zip includes a command-line executable named 7z.exe. By default, it is installed in: C:\Program Files\7-Zip\7z.exe

Ensure 7-Zip is installed and verify that this path exists on your system.

Step 2: Create the Backup Batch Script

A Windows batch file will define what files to back up, create a unique filename based on the current date, and instruct 7-Zip to generate the archive.

  1. Open Notepad.
  2. Paste the following script:
@echo off
:: Define source directory and backup destination
set "SOURCE=C:\Users\YourUsername\Documents\MyData"
set "DEST=D:\Backups"

:: Generate a reliable YYYY-MM-DD timestamp
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value') do set "DT=%%I"
set "DATESTAMP=%DT:~0,4%-%DT:~4,2%-%DT:~6,2%"

:: Create the archive name
set "ZIPNAME=Backup_%DATESTAMP%.zip"

:: Run 7-Zip command to compress files
"C:\Program Files\7-Zip\7z.exe" a -tzip "%DEST%\%ZIPNAME%" "%SOURCE%\*" -r -mx=5

exit /b

Script Breakdown:

  • SOURCE: The folder you want to back up. Update this path to match your target folder.
  • DEST: The folder where the backup file should be saved.
  • a: Tells 7-Zip to add files to an archive.
  • -tzip: Specifies the ZIP format (change to -t7z if 7z format is preferred).
  • -r: Recurses subdirectories.
  • -mx=5: Sets standard compression level (ranges from 0 for none to 9 for ultra).
  1. Save the file with the .bat extension, for example: C:\Scripts\daily_backup.bat.

Step 3: Test the Script

Before scheduling, verify the script functions properly:

  1. Double-click daily_backup.bat.
  2. Check your destination folder to ensure the new .zip file is created with today's date in the title and contains your files.

Step 4: Schedule the Script in Windows Task Scheduler

  1. Press Windows Key + R, type taskschd.msc, and press Enter.
  2. In the right-hand Actions panel, click Create Basic Task.
  3. Name: Enter Daily 7-Zip Backup and click Next.
  4. Trigger: Select Daily and click Next.
  5. Time: Choose your desired daily execution time (e.g., 11:00:00 PM) and click Next.
  6. Action: Select Start a program and click Next.
  7. Program/script: Click Browse and select your C:\Scripts\daily_backup.bat file.
  8. Start in (optional): Enter the folder path where the script is located (e.g., C:\Scripts\).
  9. Click Next, review the summary, and click Finish.

To ensure the backup runs even if you are not actively logged into the computer:

  1. Locate Daily 7-Zip Backup in the Task Scheduler Library.
  2. Right-click the task and select Properties.
  3. Under the General tab, select Run whether user is logged on or not.
  4. Check the box labeled Run with highest privileges.
  5. Click OK and enter your Windows account password when prompted.