File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python3
2
+ # -*- coding: utf8 -*-
3
+ import os
4
+ import time
5
+ import datetime
6
+ import dropbox
7
+
8
+ access_token = 'EI4xgQtc***************************-p' # dropbox access token
9
+
10
+ def main ():
11
+ # if True:
12
+ if '06:' in str (newDate ()) and int (datetime .datetime .today ().weekday ()) == 4 :
13
+ filepath = '{}{}{}' .format ('/home/toor/Documents/' , time .strftime ('%d.%m.%Y' , time .localtime ()).strip (),".gz" )
14
+ execute = 'pg_dump --dbname=postgresql://user:pass@127.0.0.1:5432/backupthis_db -Z6 > {}' .format ( filepath )
15
+ os .system (execute )
16
+
17
+ dropboxUpload (filepath );
18
+ # everything is case sensitive, make sure you insert everything correctly and to import withadminer
19
+
20
+ def newDate ():
21
+ return time .strftime ('%d.%m.%Y %H:%M' , time .localtime ())
22
+
23
+ def dropboxUpload (_filepath ):
24
+ dbx = dropbox .Dropbox (access_token )
25
+ dbx .files_upload ( open (_filepath , 'rb' ).read (), "/" + os .path .basename (_filepath ) )
26
+ print ('Backup: {} [{}]' .format (os .path .basename (_filepath ), newDate () ) );
27
+ os .system ('rm -r ' + _filepath ) # enable this if you want to delete after upload
28
+
29
+ if __name__ == '__main__' :
30
+ while True :
31
+ try :
32
+ main ()
33
+ time .sleep (3600 );
34
+ except Exception as err :
35
+ print (err )
36
+ time .sleep (3600 );
37
+ except KeyboardInterrupt :
38
+ break
You can’t perform that action at this time.
0 commit comments