Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5187ef9

Browse filesBrowse files
authored
Add files via upload
1 parent f2ff39f commit 5187ef9
Copy full SHA for 5187ef9

File tree

Expand file treeCollapse file tree

1 file changed

+38
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+38
-0
lines changed

‎serverbackup.py

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.