Automated Backups with Python: Copy Your Important Files on a Schedule

Many Hong Kong SMEs still keep client records, quotations and accounting figures in a single folder on a single computer. If that machine fails, gets hit by ransomware, or a file is deleted by accident, a decade or two of hard work can vanish in seconds. Professional backup plans cost thousands a year, but with a dozen lines of Python you can build a backup system that runs daily on its own — no manual effort, no cost.

Why back up automatically?

The biggest enemy of manual backup is forgetfulness. When you're busy, skipping a week is easy; by the time you actually need to restore, you discover the latest copy is three months old. Automated backup has three advantages:

  • Reliable — runs on a fixed schedule, no memory required
  • Fresh — a new copy every day, so you lose at most one day of data
  • Free — built on Python's built-in shutil, zero cost

Setup: install Python and schedule

If you haven't installed Python yet, head to python.org and grab the latest version — remember to tick Add Python to PATH during setup. Once done, open Command Prompt and install the schedule package:

pip install schedule

Full script

Create a new file called backup.py (Notepad is fine) and paste in this code:

import shutil
import schedule
import time
import os
from datetime import datetime

SRC = r"C:\Users\you\Documents\Important"   # folder to back up
DST_ROOT = r"D:\Backup"                     # where to back up (second drive / NAS)

def backup():
    today = datetime.now().strftime("%Y-%m-%d")
    dst = os.path.join(DST_ROOT, "backup_" + today)
    if os.path.exists(dst):
        print(today + " already backed up, skipping")
        return
    shutil.copytree(SRC, dst)
    print("Backup done -> " + dst)

schedule.every().day.at("18:00").do(backup)

print("Backup started, runs daily at 18:00")
while True:
    schedule.run_pending()
    time.sleep(60)

Line by line

  • import shutil — Python's built-in file tool that copies whole folders.
  • SRC / DST_ROOT — the two paths you customise: what to back up and where to send it. Make sure DST_ROOT points to a different drive from the source.
  • backup() — the core function. It builds a target folder name from today's date (e.g. backup_2026-09-01), checks whether it already exists, then copies the whole tree with shutil.copytree.
  • schedule.every().day.at("18:00") — schedules backup() to run every day at 6pm.
  • while True — keeps the script alive, waking every 60 seconds to check for pending jobs. This loop barely uses any resources.

Advanced: back up only changed files

If your folder is large, copying everything daily wastes space. To save space, use shutil.copy2 with os.walk to compare modification times and copy only changed files:

import os
import shutil

SRC = r"C:\Users\you\Documents\Important"
DST = r"D:\Backup\incremental"

for root, dirs, files in os.walk(SRC):
    rel = os.path.relpath(root, SRC)
    target_dir = os.path.join(DST, rel)
    os.makedirs(target_dir, exist_ok=True)
    for f in files:
        src_f = os.path.join(root, f)
        dst_f = os.path.join(target_dir, f)
        if (not os.path.exists(dst_f)) or (os.path.getmtime(src_f) > os.path.getmtime(dst_f)):
            shutil.copy2(src_f, dst_f)

This version skips unchanged files and only copies new ones, so it won't get slower day after day.

How to make it truly run every day

The simplest option is the while True version above — just leave it running on a machine that stays on. If you prefer OS-level scheduling on Windows:

  1. Press Win and search for "Task Scheduler"
  2. "Create Basic Task" → set the trigger to "Daily" at 18:00
  3. Set the action to "Start a program", with python as the program and C:\path\backup.py as the argument

Mac / Linux users can do the same with a single cron line.

Three safety tips

  • Store separately — always back up to a different drive or NAS, and ideally mirror another copy to the cloud to follow the "3-2-1" rule.
  • Test restores regularly — don't wait for a disaster to discover your backup is corrupted; do a trial restore each quarter.
  • Encrypt sensitive data — client privacy and accounting data should be encrypted before backing up.

Summary

Automated backup isn't just for big companies. With a dozen lines of Python you get a daily, auto-named, duplicate-skipping backup system that costs nothing and is just as reliable as a paid plan. From today, stop relying on memory to protect your business data.