Spaces:
Sleeping
Sleeping
File size: 2,804 Bytes
fe617ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import pexpect
import os
import sys
def sync_to_server():
host = "connect.nmb2.seetacloud.com"
port = "26578"
user = "root"
password = "9Dml+WZeqp5b"
local_path = os.getcwd()
remote_path = "/root/book-rec-with-LLMs"
print(f"Syncing to {user}@{host}:{port}...")
# 1. Create remote directory
# ssh -p PORT user@host "mkdir -p remote_path"
cmd_mkdir = f"ssh -p {port} {user}@{host} 'mkdir -p {remote_path}'"
child = pexpect.spawn(cmd_mkdir)
i = child.expect(['password:', 'continue connecting', pexpect.EOF, pexpect.TIMEOUT])
if i == 1: # verify host key
child.sendline('yes')
child.expect('password:')
if i == 0 or i == 1:
child.sendline(password)
child.expect(pexpect.EOF)
print("Remote directory created.")
# 2. Sync Code (src, scripts, requirements.txt)
# Using scp -r -P PORT ...
# Exclude files handled by .gitignore if using rsync, but scp is simpler for now
# Let's sync folders individually to be safe
# 2. Sync Code
folders = ['src', 'scripts']
for folder in folders:
print(f"Syncing {folder}...")
cmd_scp = f"scp -r -P {port} {local_path}/{folder} {user}@{host}:{remote_path}/"
child = pexpect.spawn(cmd_scp, timeout=300)
i = child.expect(['password:', 'continue connecting', pexpect.EOF, pexpect.TIMEOUT])
if i == 1:
child.sendline('yes')
child.expect('password:')
if i == 0 or i == 1:
child.sendline(password)
child.expect(pexpect.EOF)
print(f"Synced {folder}.")
# 3. Sync Data (Only necessary files)
print("Syncing data files (rec/ and books_processed.csv)...")
# Ensure data dir exists
cmd_mkdir_data = f"ssh -p {port} {user}@{host} 'mkdir -p {remote_path}/data'"
child = pexpect.spawn(cmd_mkdir_data)
child.expect('password:')
child.sendline(password)
child.expect(pexpect.EOF)
# Sync books_processed.csv
print("Syncing books_processed.csv (350MB+)...")
cmd_scp_books = f"scp -P {port} {local_path}/data/books_processed.csv {user}@{host}:{remote_path}/data/"
child = pexpect.spawn(cmd_scp_books, timeout=1200) # 20 mins
child.expect('password:')
child.sendline(password)
child.expect(pexpect.EOF)
# Sync rec/ folder
print("Syncing data/rec/ folder (1.5GB+)...")
cmd_scp_rec = f"scp -r -P {port} {local_path}/data/rec {user}@{host}:{remote_path}/data/"
child = pexpect.spawn(cmd_scp_rec, timeout=3600) # 60 mins
child.expect('password:')
child.sendline(password)
child.expect(pexpect.EOF)
print("Sync Completed!")
print("Sync Completed!")
if __name__ == "__main__":
sync_to_server()
|