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/*

TarPipe

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]:
'Last login: Tue Feb  3 19:17:33 2015 from 203-97-200-144.dsl.clear.net.nz\r\r\n'

In [10]:
ouput.send('uptime')


Out[10]:
6

In [11]:
ouput.send('chdir /getsdrawn')


Out[11]:
16

In [12]:
opftp = sshgetdrn.open_sftp()

In [13]:
for i in opftp.listdir('/home/wcmckee/getsdrawndotcom/'):
    print i


style.css
googlebb8fa72eb382e061.html
imgs
test.txt
sitemap.xml
index.html

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


2015-02-03T19:25:05.046523+00:00

In [73]:
utc.weekday()


Out[73]:
1

In [76]:
utc.date()


Out[76]:
datetime.date(2015, 2, 3)

In [78]:
utc.datetime


Out[78]:
datetime.datetime(2015, 2, 3, 19, 25, 5, 46523, tzinfo=tzutc())

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)


its false

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 [ ]: