#!/bin/bash # Variables RCLONE_DIR="/mnt/data-pool/rclone" RCLONE_LOGS="${RCLONE_DIR}/logs" RCLONE_CONFIG="${RCLONE_DIR}/rclone.conf" RCLONE_BIN="${RCLONE_DIR}/rclone" RCLONE_COMMAND="${RCLONE_BIN} --config ${RCLONE_CONFIG} --log-level INFO --log-file" PIDFILE="${RCLONE_DIR}/rclone.sh.pid" # removes pid file and exit cleany function clean-up { # Gzip Log files find ${RCLONE_LOGS} -type f ! -name '*.gz' -exec pigz "{}" \; # remove the pid file rm -f ${PIDFILE} # exit with clean code exit 0 } function gzipVMbackups { # Waiting for the backup programs to stop running, will recheck every 5 minutes while [ -f "/mnt/data-pool/esxi/backups/ghettoVCB.work/GauntESXi01/pid" ] || [ -f "/mnt/data-pool/esxi/backups/ghettoVCB.work/GauntESXi02/pid" ]; do sleep 600 done # loop through VM backups and tar/gzip them to single file for dir in /mnt/data-pool/esxi/backups/*/*/; do if [ -d "$dir" ]; then # get the folder name of the backup base=$(basename "${dir}") # had to cd into the directoy since tar -C $dir was not working for me with relative path cd "${dir%/*/}" # create the tar and pipe into pigz for multi-threaded gzip tar cf - "${base}" | pigz > "${dir%/}.gz" # if the tar/gzip was successful, delete the backup directory if [ $? -eq 0 ] && [ -f "${dir%/}.gz" ]; then rm -rf "${dir}" fi fi done } # Look for exits in the program and make sure to call the clean-up function trap clean-up SIGHUP SIGINT SIGTERM # Check to see if app is running or not if [ -f ${PIDFILE} ]; then PID=$(cat "${PIDFILE}") ps -p "${PID}" > /dev/null 2>&1 if [ $? -eq 0 ]; then # "Previous job, ${PID}, is already running" exit 1 else ## Process not found assume not running echo $$ > "${PIDFILE}" if [ $? -ne 0 ]; then # "Could not create PID file" exit 1 fi fi else echo $$ > "${PIDFILE}" if [ $? -ne 0 ]; then # "Could not create PID file" exit 1 fi fi # Upload EncFS encrypted media to Google Drive ${RCLONE_COMMAND} "${RCLONE_LOGS}/media/rclone_media_gd_`date +%Y%m%d-%H%M%S`.log" sync /mnt/media/plex/local_media/ media: # Upload rclone encrypted esxi backups to Google Drive # Wait for backup script to finish so gzip can compress gzipVMbackups ${RCLONE_COMMAND} "${RCLONE_LOGS}/esxi/rclone_esxi_gd_`date +%Y%m%d-%H%M%S`.log" copy /mnt/data-pool/esxi/backups/ gauntnas:"Backups/ESXi Backups/" # Upload rclone encrypted software to Google Drive ${RCLONE_COMMAND} "${RCLONE_LOGS}/software/rclone_software_gd_`date +%Y%m%d-%H%M%S`.log" --backup-dir gauntnas:Deleted/`date +%Y%m%d-%H%M%S`/Software/ sync /mnt/data-pool/software/ gauntnas:Software # Upload rclone encrypted seafile files to Google Drive and BackBlaze B2 ${RCLONE_COMMAND} "${RCLONE_LOGS}/seafile/rclone_seafile_gd_`date +%Y%m%d-%H%M%S`.log" sync /mnt/data-pool/seafile/ gauntnas:seafile ${RCLONE_COMMAND} "${RCLONE_LOGS}/seafile/rclone_seafile_b2_`date +%Y%m%d-%H%M%S`.log" --transfers 10 --fast-list sync /mnt/data-pool/seafile/ b2-crypt: # exit the program clean-up