Browse Source

use python seedbox syncing script

Josh Bicking 1 year ago
parent
commit
466b2a9a2e
4 changed files with 41 additions and 56 deletions
  1. 1 1
      radarr.yaml
  2. 39 0
      seedbox_sync.py
  3. 1 1
      sonarr.yaml
  4. 0 54
      sonarr_sync.sh

+ 1 - 1
radarr.yaml

@@ -16,7 +16,7 @@ spec:
     spec:
     spec:
       containers:
       containers:
       - name: radarr
       - name: radarr
-        image: lscr.io/linuxserver/radarr:develop-4.3.1.6822-ls79
+        image: lscr.io/linuxserver/radarr:nightly-4.4.0.6875-ls428
         ports:
         ports:
         - containerPort: 7878
         - containerPort: 7878
           name: http-web-svc
           name: http-web-svc

+ 39 - 0
seedbox_sync.py

@@ -0,0 +1,39 @@
+import subprocess
+import sys
+
+# Usage: sonarr_sync.py my-seedbox /seedbox/path/to/data /local/working /local/metadata /local/data
+# Get all file names in HOST:HOST_DATA_PATH
+# Get all previously processed file names in LOCAL_METADATA_PATH
+# Diff the above to get newly added files
+# For each new file:
+#   Copy file to LOCAL_WORKING_PATH (used in case of transfer failure)
+#   Add file name to LOCAL_METADATA_PATH
+#   Move file to LOCAL_DATA_PATH
+
+if len(sys.argv) != 6:
+    print("One or more args are undefined")
+    sys.exit(1)
+
+host, host_data_path, local_working_path, local_metadata_path, local_data_path = sys.argv[1:6]
+
+r = subprocess.run(["ssh", host, "bash", "-c", f"IFS=$'\n'; ls {host_data_path}"], stdout=subprocess.PIPE, check=True)
+
+available = {f for f in r.stdout.decode().split('\n') if f}
+
+r = subprocess.run(["bash", "-c", f"IFS=$'\n'; ls {local_metadata_path}"], stdout=subprocess.PIPE, check=True)
+
+processed = {f for f in r.stdout.decode().split('\n') if f}
+
+new = available - processed
+
+for new_file in new:
+    if not new_file:
+        continue
+
+    print(f"Processing: {new_file}")
+    subprocess.run(["bash", "-c", f"rsync -rsvv {host}:{host_data_path}/{new_file} {local_working_path}"], check=True)
+    r = subprocess.run(["bash", "-c", f"touch {local_metadata_path}/{new_file}"], check=True)
+
+    print(f"Moving to ready: {new_file}")
+    subprocess.run(["bash", "-c", f"rsync -r {local_working_path}/{new_file} {local_data_path}"], check=True)
+    subprocess.run(["bash", "-c", f"rm -rf {local_working_path}/{new_file}"], check=True)

+ 1 - 1
sonarr.yaml

@@ -16,7 +16,7 @@ spec:
     spec:
     spec:
       containers:
       containers:
       - name: sonarr
       - name: sonarr
-        image: lscr.io/linuxserver/sonarr:develop-4.0.0.307-ls362
+        image: lscr.io/linuxserver/sonarr:develop-4.0.0.344-ls383
         ports:
         ports:
         - containerPort: 8989
         - containerPort: 8989
           name: http-web-svc
           name: http-web-svc

+ 0 - 54
sonarr_sync.sh

@@ -1,54 +0,0 @@
-#!/bin/bash -e
-
-# Usage: sonarr_sync.sh my-seedbox /seedbox/path/to/data /local/working /local/metadata /local/data
-# Get all file names in HOST:HOST_DATA_PATH
-# Get all previously processed file names in LOCAL_METADATA_PATH
-# Diff the above to get newly added files
-# For each new file:
-#   Copy file to LOCAL_WORKING_PATH (used in case of transfer failure)
-#   Add file name to LOCAL_METADATA_PATH
-#   Move file to LOCAL_DATA_PATH
-
-
-HOST=$1
-HOST_DATA_PATH=$2
-LOCAL_WORKING_PATH=$3
-LOCAL_METADATA_PATH=$4
-LOCAL_DATA_PATH=$5
-
-if [[ -z $HOST || -z $HOST_DATA_PATH || -z $LOCAL_WORKING_PATH || -z $LOCAL_METADATA_PATH || -z $LOCAL_DATA_PATH ]]; then
-  echo 'one or more args are undefined'
-  exit 1
-fi
-
-ssh $HOST bash -c 'OIFS=$IFS; IFS=$'"'\n'"'; available=($(ls '$HOST_DATA_PATH')); IFS=$OIFS; declare -p available' > /tmp/available
-source /tmp/available
-rm /tmp/available
-
-#declare -p available
-
-
-bash -c 'OIFS=$IFS; IFS=$'"'\n'"'; processed=($(ls '$LOCAL_METADATA_PATH')); IFS=$OIFS; declare -p processed' > /tmp/processed
-source /tmp/processed
-rm /tmp/processed
-
-#declare -p processed
-
-OIFS=$IFS
-IFS=$'\n'
-new=($(comm --nocheck-order -13 <(printf '%s\n' "${processed[@]}" | LC_ALL=C sort) <(printf '%s\n' "${available[@]}" | LC_ALL=C sort)))
-IFS=$OIFS
-
-#declare -p new
-
-for i in "${new[@]}"
-do
-	if [ ! -z "$i" ]; then
-		echo "Processing: $i"
-		rsync -rsvv "$HOST:$HOST_DATA_PATH/$i" $LOCAL_WORKING_PATH
-		touch "$LOCAL_METADATA_PATH/$i"
-		echo "Moving to ready: $i"
-		rsync -r "$LOCAL_WORKING_PATH/$i" "$LOCAL_DATA_PATH"
-		rm -rf "$LOCAL_WORKING_PATH/$i"
-	fi
-done