In [1]:
#%%bash
#tar zcvf - /home/public/cam | ssh pi@10.1.1.14 "cat > /home/pi/sativacam.tar.gz"
#sudo rm /home/public/cam/*
This script creates a .tar.gz of certain folders and allows for easy search of the files backed up.
Currently focus on on motion but getsdrawn would also help.
TODO
ssh and tarpipe into redditgetsdrawn when it hits midnight on server time (GMT).
In [2]:
import tarfile
import time
import os
import getpass
import paramiko
import arrow
curtime = time.strftime("%d-%b-%Y-%H", time.gmtime())
In [3]:
sshgetdrn = paramiko.SSHClient()
In [4]:
sshgetdrn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
In [5]:
usrg = getpass.getuser()
In [6]:
sshgetdrn.connect('128.199.60.12', username='wcmckee')
In [7]:
sup = sshgetdrn.exec_command('uptime')
In [8]:
ouput = sshgetdrn.invoke_shell()
In [9]:
ouput.recv(1000)
Out[9]:
In [10]:
ouput.send('uptime')
Out[10]:
In [11]:
ouput.send('chdir /getsdrawn')
Out[11]:
In [12]:
opftp = sshgetdrn.open_sftp()
In [13]:
for i in opftp.listdir('/home/wcmckee/getsdrawndotcom/'):
print i
In [14]:
utc = arrow.utcnow()
I want datetime printed as year-month-day-hour-min.
Currently shows on getsdrawn as : Updated Tue, 03 Feb 2015 19:00:12 +0000.
Folder format:
In [ ]:
In [71]:
print utc
In [73]:
utc.weekday()
Out[73]:
In [76]:
utc.date()
Out[76]:
In [78]:
utc.datetime
Out[78]:
In [8]:
backdir = ('/home/' + usrg + '/backup-motion/')
In [10]:
if os.path.isdir(backdir) == True:
print 'its true'
else:
print 'its false'
os.mkdir(backdir)
In [11]:
tar = tarfile.open(backdir + curtime + ".tar.gz", "w:gz")
tar.add("/home/wcmckee/mot/", arcname="TarName")
tar.close()
#os.rmdir('/home/shared/cam')
In [2]:
In [ ]: