Enhanced backup.py

#!/usr/bin/env python
import subprocess, sys, re, pathlib
from datetime import datetime
backup_folder = "/media/Backup/Windows_10_backup"
if len(sys.argv) != 2:
    print("No input drive.")
    exit(0)
if not pathlib.Path(sys.argv[1]).exists():
    print(sys.argv[1] + " doesn't exist!")
    exit(0)
if_file = str(pathlib.Path.resolve(pathlib.Path(sys.argv[1])))
d = str(datetime.now().date())
fdisk = subprocess.run('fdisk -l ' + if_file, stdout=subprocess.PIPE, shell=True)
fdisk = fdisk.stdout.decode().strip()
parts = re.findall(r'(^'+if_file+'\d)', str(fdisk), re.MULTILINE)
if not pathlib.Path(backup_folder + "/" + d).exists():
    pathlib.Path(backup_folder + "/" + d).mkdir()
    for p in parts:
        splitter = p.split("/")
        out_file = backup_folder + "/" + d + "/" + splitter[len(splitter) - 1] + ".partimg"
        subprocess.call('partimage -b -d save ' + p + ' ' + out_file, shell=True)

Does it work if you don’t use a symlink? It works if you do use a symlink, so you can use /dev/disk/by-id. That way if a reboot causes it to be changed, you can still automate the backup. Or you don’t have to type fdisk -l to see what it is every time you backup. You can make it change by plugging a USB drive in and rebooting.