- Download the
backup.py
script and save it wherever you want to - Make it executable by running:
chmod +x <path-to-backup.py>
# Run the following command to learn about your options
$ ./backup.py --help
#!/usr/bin/env python3 | |
import argparse | |
import os | |
import shutil | |
from distutils.dir_util import copy_tree | |
from shutil import copy2 | |
_DEFAULT_BACKUP_DEST = "/Volumes/Audio/Cubase Settings" | |
_DEFAULT_CUBASE_VERSION = 10 | |
_SCRIPT_PATH = os.path.realpath(__file__) | |
class Config: | |
def __init__(self, backup_destination: str, cubase_version: str, clear: bool): | |
self.backup_destination = backup_destination | |
self.cubase_version = cubase_version | |
self.clear = clear | |
def main(): | |
config = _parse_args() | |
dest = config.backup_destination | |
if not os.path.exists(dest): | |
print(f"Backup destination '{dest}' does not exist. Please create it and run the backup again.") | |
exit(0) | |
print(f"Backing up files to '{dest}'") | |
_run_backup(config) | |
print("Done.") | |
def _run_backup(config): | |
paths_map = _paths_for(config) | |
for src in paths_map: | |
dst = paths_map[src] | |
if not os.path.exists(src): | |
print(f"Source path '{src}' does not exist on this system. Skipping...") | |
continue | |
if src == dst: | |
print(f"Source path '{src}' and destination '{dst}' are the same. Skipping...") | |
continue | |
dst = paths_map[src] | |
if os.path.isdir(src): | |
if config.clear and os.path.exists(dst): | |
print(f"Deleting destination directory '{dst}'...") | |
shutil.rmtree(dst) | |
print(f"Copying files from '{src}' to '{dst}'...") | |
copy_tree(src=src, dst=dst, preserve_mode=1, preserve_times=1, update=1, dry_run=0) | |
else: | |
print(f"Copying file '{src}' to '{dst}'...") | |
copy2(src, dst) | |
def _parse_args(): | |
parser = argparse.ArgumentParser(description='Process some integers.') | |
parser.add_argument( | |
'--dest', '-d', | |
dest='dest', | |
default=_DEFAULT_BACKUP_DEST, | |
action='store', | |
help='full path to destination directory.' | |
) | |
parser.add_argument( | |
'--clear', '-c', | |
dest='clear', | |
default=False, | |
action='store_true', | |
help='delete destination directories before copying.' | |
) | |
parser.add_argument( | |
'--cubase-version', '-v', | |
dest='cubase_version', | |
default="10", | |
action='store', | |
help='Cubase version to backup settings for.' | |
) | |
args = parser.parse_args() | |
return Config( | |
backup_destination=args.dest, | |
cubase_version=args.cubase_version, | |
clear=args.clear, | |
) | |
def _paths_for(config: Config): | |
src = os.path.expanduser(os.path.join("~/Library")) | |
dst = os.path.expanduser(os.path.join(config.backup_destination, "Library")) | |
return { | |
f"{src}/Preferences/Cubase {config.cubase_version}/Project Templates": | |
f"{dst}/Preferences/Cubase {config.cubase_version}/Project Templates", | |
f"{src}/Application Support/Steinberg/Track Presets": | |
f"{dst}/Application Support/Steinberg/Track Presets", | |
f"{src}/Audio/Steinberg": f"{dst}/Audio/Steinberg", | |
f"{src}/Audio/Presets": f"{dst}/Audio/Presets", | |
f"{_SCRIPT_PATH}": f"{config.backup_destination}/backup.py", | |
} | |
if __name__ == '__main__': | |
main() |