2014-12-28 06:32:17 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# sync-pics: A script to copy my personal files across various redundant hard
|
|
|
|
# drives.
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
from collections import OrderedDict
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# --- Start Configurable Parameters --- #
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
# The "master" drive where all source files are synced from.
|
|
|
|
MASTER = "Midnight"
|
|
|
|
|
|
|
|
# We use rsync to copy files from the master drive to all the slaves. This is
|
|
|
|
# the base rsync command used for most copy operations.
|
|
|
|
RSYNC = "rsync -avu --delete {source}/ {destination}/"
|
|
|
|
|
|
|
|
# The listing of all drives/paths to sync stuff to.
|
|
|
|
TARGETS = OrderedDict([
|
|
|
|
# Local hard disks. Just do a simple rsync of all files in their paths.
|
|
|
|
("Midnight", dict(
|
|
|
|
path = "/mnt/Midnight/Images/Organized",
|
|
|
|
)),
|
|
|
|
("Cyro", dict(
|
2015-11-18 03:03:44 +00:00
|
|
|
path = "/media/kirsle/Cyro/Pictures/Organized",
|
2014-12-28 06:32:17 +00:00
|
|
|
)),
|
|
|
|
("Obelisk", dict(
|
2015-11-18 03:03:44 +00:00
|
|
|
path = "/media/kirsle/Obelisk/Redundant/Images/Organized",
|
2015-07-11 20:14:24 +00:00
|
|
|
rsync = "rsync -avu --no-p --delete {source}/ \"{destination}/\"",
|
2014-12-28 06:32:17 +00:00
|
|
|
)),
|
|
|
|
("Rosewill", dict(
|
2015-11-18 03:03:44 +00:00
|
|
|
path = "/media/kirsle/Rosewill/Redundant/Images/Organized",
|
2014-12-28 06:32:17 +00:00
|
|
|
)),
|
|
|
|
|
|
|
|
# Dropbox volumes.
|
|
|
|
("Dropbox", dict(
|
2015-11-04 21:20:57 +00:00
|
|
|
path = "/home/kirsle/Dropbox/Photos/Organized",
|
2014-12-28 06:32:17 +00:00
|
|
|
rsync = "rsync -avu --delete --exclude .X {source}/ {destination}/",
|
|
|
|
)),
|
|
|
|
("Vault", dict(
|
2015-11-04 21:20:57 +00:00
|
|
|
path = "/home/kirsle/Dropbox Vault",
|
2014-12-28 06:32:17 +00:00
|
|
|
rsync = "rsync -avu --delete {source}/.X/ \"{destination}/\"",
|
|
|
|
)),
|
2015-10-20 03:56:09 +00:00
|
|
|
|
|
|
|
# Owncloud backup.
|
|
|
|
("Owncloud", dict(
|
2015-11-04 21:20:57 +00:00
|
|
|
path = "/home/kirsle/ownCloud/Photos/Organized",
|
2015-10-20 03:56:09 +00:00
|
|
|
rsync = "rsync -avu --delete --exclude .X {source}/ {destination}/",
|
|
|
|
)),
|
2014-12-28 06:32:17 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# --- End Configurable Parameters --- #
|
|
|
|
#######################################
|
|
|
|
|
|
|
|
def copy_hdds():
|
|
|
|
# Pair up all of the master->slave relationships.
|
|
|
|
pairs = list()
|
|
|
|
for source in TARGETS:
|
|
|
|
if source == MASTER:
|
|
|
|
continue
|
|
|
|
|
|
|
|
pairs.append([MASTER, source])
|
|
|
|
|
|
|
|
# Synchronize!
|
|
|
|
for pair in pairs:
|
|
|
|
source, destination = pair
|
|
|
|
print("\n### Synchronize: {} -> {}".format(source, destination))
|
|
|
|
|
|
|
|
# Get their filesystem paths.
|
|
|
|
source_path = TARGETS[source]["path"]
|
|
|
|
destination_path = TARGETS[destination]["path"]
|
|
|
|
|
|
|
|
# Is either path not mounted?
|
|
|
|
if not os.path.isdir(source_path):
|
|
|
|
print("Source {} is not mounted.".format(source_path))
|
|
|
|
continue
|
|
|
|
if not os.path.isdir(destination_path):
|
|
|
|
print("Destination {} is not mounted.".format(destination_path))
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Get the rsync command.
|
|
|
|
command = TARGETS[destination].get("rsync", RSYNC)
|
|
|
|
|
|
|
|
# Run it!
|
|
|
|
system(command.format(source=source_path, destination=destination_path))
|
|
|
|
|
|
|
|
|
|
|
|
def system(command):
|
|
|
|
print("$", command)
|
|
|
|
subprocess.call(command, shell=True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
copy_hdds()
|