docker_images/backups/rsyncvolumes/remote.py

19 lines
675 B
Python
Raw Normal View History

from os import environ
from subprocess import Popen
from shlex import split as shplit
# Remote syncing, when needed
def sync():
""" Remote syncing """
DEST = environ.get('DEST')
REMOTE_HOST = environ.get('REMOTE_HOST', False)
if REMOTE_HOST:
REMOTE_USER = environ.get('REMOTE_USER')
REMOTE_PASS = environ.get('REMOTE_PASS')
print('Remote host %s configured : will sync with it' % REMOTE_HOST)
command = ('sshpass -p %s rsync -av --delete -e '
'"ssh -p 23 -o StrictHostKeyChecking=no" '
'%s %s@%s:./backups') % (REMOTE_PASS, DEST, REMOTE_USER, REMOTE_HOST)
Popen(shplit(command))