-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresql-backup.py
More file actions
38 lines (32 loc) · 1.33 KB
/
Copy pathpostgresql-backup.py
File metadata and controls
38 lines (32 loc) · 1.33 KB
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
#!/usr/bin/python3
# -*- coding: utf8 -*-
import os
import time
import datetime
import dropbox
access_token = 'EI4xgQtc****************************-p' # dropbox access token
def main():
# if True:
if '04:' in str(newDate()) and int(datetime.datetime.today().weekday()) == 4:
filepath = '{}{}{}'.format('/home/username/Documents/', time.strftime('%d.%m.%Y', time.localtime()).strip(),".gz") # add your username :D
execute = 'pg_dump --dbname=postgresql://user:pass@127.0.0.1:5432/backupthis_db -Z6 > {}'.format( filepath )
os.system(execute)
dropboxUpload(filepath);
# everything is case sensitive, make sure you insert everything correctly and to import withadminer
def newDate():
return time.strftime('%d.%m.%Y %H:%M', time.localtime())
def dropboxUpload(_filepath):
dbx = dropbox.Dropbox(access_token)
dbx.files_upload( open(_filepath, 'rb').read(), "/" + os.path.basename(_filepath) )
print('Backup: {} [{}]'.format(os.path.basename(_filepath), newDate() ) );
os.system('rm -r ' + _filepath) # enable this if you want to delete after upload
if __name__ == '__main__':
while True:
try:
main()
time.sleep(3600);
except Exception as err:
print(err)
time.sleep(3600);
except KeyboardInterrupt:
break