Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DiskBackupMonitor.py

Dev Note

Creating this script was primarily done as a way to speed up the process of backing up my personal DVD and bluray collection for conversion into a format that I could then upload to my personal Jellyfin media server. I wanted to keep all of the .iso files in case something ever happened to the original disks and I needed to burn a new copy (harder to do with blurays, I know). Ultimately, though, I want to be able to access and enjoy everything in my physical collection without needing to go and find the specific disk on the shelf, put it in the player (usually a game system where I already have a game disk inserted and running), and start it there.

While I'm not necessarily new to Python or Powershell, I also wouldn't necessarily call myself an expert either. The development of these scripts was a learning experience, thus they may not be the most efficient or elegant, but they work for what I needed them to do. With this script, I have been able to backup nearly 450 disks of my collection (over 1600 between various movies, TV series, anime, etc.) in the span of about 3-4 weeks, and the only effort I have to use for the backup process is just inserting a new disk when the script says to, and make sure I'm not running out of disk space for the backups.

If you choose to use this script and have any issues, feel free to open an issue with any questions or problems you may have and I'll do my best to address them as I can. Please be patient with me as this is a side project in addition to my full time job.

Thanks and good luck!

Prerequisites:

  1. Requires running on Windows 10 or above with Python 3.8 or greater

  2. Requires MakeMKV for backup and ImgBurn for bluray to ISO conversion (see process below)

How it works:

  1. Monitors disk drive for inserted disks

    • If a disk with the same disk name has already been backed up, disk is ejected and waits for next disk

    • Some disks may share the same disk name (production companies have no standards for this), so if the disk is genuinely different, the existing backup will need to be renamed.

  2. Backs up to disk to local working directory (DVDs to ISO, Blurays to folder)

  3. Starts background threads to:

    • If disk is a DVD, moves ISO file to network backup directory

    • If disk is a bluray, converts to ISO file and then moves to network backup directory

  4. Ejects disk and waits for next disk

After backup, the script monitors two folders:

  1. backup_path - where newly backed up ISO files are copied to
  2. converted_path - where the ISO files that have been converted to play on Jellyfin or other personal media server should be manually copied to

The backup_path location acts as a queue for files to be converted to use in Jellyfin or other personal media server, while the converted_path location is the "done" storage.

All successes and failures are written to logs files Each disk backup also has its own log file

Installation

To install, download the zipped files from the repo and unzip.

Configuration

Configuration is done via config.ini file. An example of this file is included in this repo. Copy this file into "config.ini" before use.

File Directories:

- disk_drive = Drive letter for the specific optical drive to be used for backup
- working_dir = Temp directory where backup files are stored before being copied to long-term storage location
- backup_path = Directory where completed backups are moved to
- converted_path = Secondary directory where backups that have been converted for use in Jellyfin or other personal media server should be moved to for continued tracking by this script

Logs:

- failed_log = Path and filename for failed backups to log failure message
- success_log = Path and filename for successful backups to log success message
- disk_logs_dir = Directory to move individual disk backup message logs to after completed or failed backup

Usage

Once the configuration file has been setup, run the following command in the command line:

python DiskBackupMonitor.py

  1. This will start script and wait for new disk to be inserted into the expected drive.

  2. Once a disk is inserted, the script will check the backup_path and converted_path directories for any ISO files matching the name of the inserted disk.

    • If existing backup is found, the script will eject the disk and wait for new disk. If the inserted disk was, in fact, new then the existing backup should be renamed to allow script to proceed.
  3. MakeMKV backup will proceed to run.

    • If the disk is a DVD, the backup will run directly to a .iso file. If the disk is a bluray, the backup will run to a folder with the name including .iso.

    • Should the backup fail to complete, a message will be logged to the failure_log file and the failed backup files will be cleaned up, the disk ejected, and the script will return to step 1 to wait for a new disk.

  4. After the backup has been completed, the script will verify if the backup was from a DVD (.iso file) or bluray (folder). If DVD, the script will move on to step 5. If bluray, the backup will perform an intermediate step to run ImgBurn to convert the folder into a .iso file and remove the original backup folder.

  5. The script will then copy the backed up .iso file to the configured backup_path location for storage. Once moved, the individual disk log will also be moved to the configured location and a message will be inserted into the configured success_log file.

Multiple Optical Disks Installed

If your system has multiple optical drives installed, on occasion MakeMKV can mistake which drive should be utilized. If the backup appears to start but then fails without an error, run the following MakeMKV command to get the list of defined drives:

makemkvcon -r --cache=1 info disc:9999

This will take a few seconds to process and then will output several lines of text. The lines of interest look like this:

DRV:0,0,999,0,"DVD+R-DL HL-DT-ST DVDRAM GUD0N 1.00 KZTG6705539","","F:"
DRV:1,2,999,12,"BD-RE HL-DT-ST BD-RE  WH16NS40 1.04 KLTK4BD2336","THE_LION_KING","E:"

Starting from 0 as the first drive in the list, count down the list of entries until you find the drive that shows the disk name of the disk you're trying to backup. In the example above, the desired drive is number 1, which shows "The Lion King" is inserted.

Then, use this command to start the backup monitor script:

python DiskBackupMonitor.py 1

where the number at the end is the number corresponding to the drive found in the list.

DriveControl.py

This script is an optional utility meant to allow for opening, closing, and testing of the optical drive via command line.

Usage

The script takes the following commands:

- open [drive letter] - Open the disk drive
- close [drive letter] - Close the disk drive
- test [drive letter] - Display the Windows drive information for the drive
- list - Display a list of the optical drives Windows is aware of

NOTE: The order the drives appear in the list command (i.e. drive letter order) doesn't always match what MakeMKV finds in it's list. If multiple drives are installed, please see Multiple Optical Disks Installed

Example:

W:\Scripts>python DriveControl.py open E
Disk drive: E:
Disk drive opened.

W:\Scripts>python DriveControl.py close E
Disk drive: E:
Disk drive closed.

W:\Scripts>python DriveControl.py test E
Disk drive: E:
Disk index: 0

instance of Win32_LogicalDisk
{
        Access = 1;
        Caption = "E:";
        Compressed = FALSE;
        CreationClassName = "Win32_LogicalDisk";
        Description = "CD-ROM Disc";
        DeviceID = "E:";
        DriveType = 5;
        FileSystem = "UDF";
        FreeSpace = "0";
        MaximumComponentLength = 254;
        MediaType = 11;
        Name = "E:";
        Size = "44546719744";
        SupportsDiskQuotas = FALSE;
        SupportsFileBasedCompression = FALSE;
        SystemCreationClassName = "Win32_ComputerSystem";
        SystemName = "MSI";
        VolumeDirty = FALSE;
        VolumeName = "THE_LION_KING";
        VolumeSerialNumber = "6A82EBE7";
};


W:\Scripts>python DriveControl.py list

instance of Win32_LogicalDisk
{
        Access = 1;
        Caption = "E:";
        Compressed = FALSE;
        CreationClassName = "Win32_LogicalDisk";
        Description = "CD-ROM Disc";
        DeviceID = "E:";
        DriveType = 5;
        FileSystem = "UDF";
        FreeSpace = "0";
        MaximumComponentLength = 254;
        MediaType = 11;
        Name = "E:";
        Size = "44546719744";
        SupportsDiskQuotas = FALSE;
        SupportsFileBasedCompression = FALSE;
        SystemCreationClassName = "Win32_ComputerSystem";
        SystemName = "MSI";
        VolumeDirty = FALSE;
        VolumeName = "THE_LION_KING";
        VolumeSerialNumber = "6A82EBE7";
};


instance of Win32_LogicalDisk
{
        Caption = "F:";
        CreationClassName = "Win32_LogicalDisk";
        Description = "CD-ROM Disc";
        DeviceID = "F:";
        DriveType = 5;
        MediaType = 11;
        Name = "F:";
        SystemCreationClassName = "Win32_ComputerSystem";
        SystemName = "MSI";
};

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages