mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-31 22:20:12 +00:00
Adding python backup for postgresql. This will be much easier to run automatedly.
This commit is contained in:
parent
f7be029c58
commit
de89b527ff
2 changed files with 25 additions and 4 deletions
|
@ -265,7 +265,7 @@ class Feed(models.Model):
|
|||
# history.delete()
|
||||
if status_code not in (200, 304):
|
||||
fetch_history = map(lambda h: h.status_code,
|
||||
MFeedFetchHistory.objects(feed_id=self.pk)[:10])
|
||||
MFeedFetchHistory.objects(feed_id=self.pk)[:50])
|
||||
self.count_errors_in_history(fetch_history, status_code, 'feed')
|
||||
elif self.has_feed_exception:
|
||||
self.has_feed_exception = False
|
||||
|
@ -284,7 +284,7 @@ class Feed(models.Model):
|
|||
|
||||
if status_code not in (200, 304):
|
||||
fetch_history = map(lambda h: h.status_code,
|
||||
MPageFetchHistory.objects(feed_id=self.pk)[:10])
|
||||
MPageFetchHistory.objects(feed_id=self.pk)[:50])
|
||||
self.count_errors_in_history(fetch_history, status_code, 'page')
|
||||
elif self.has_page_exception:
|
||||
self.has_page_exception = False
|
||||
|
@ -292,8 +292,8 @@ class Feed(models.Model):
|
|||
self.save()
|
||||
|
||||
def count_errors_in_history(self, fetch_history, status_code, exception_type):
|
||||
non_errors = [h for h in fetch_history if int(h) in (200, 304)]
|
||||
errors = [h for h in fetch_history if int(h) not in (200, 304)]
|
||||
non_errors = [h for h in fetch_history if int(h) in (200, 304)]
|
||||
errors = [h for h in fetch_history if int(h) not in (200, 304)]
|
||||
|
||||
if len(non_errors) == 0 and len(errors) >= 1:
|
||||
if exception_type == 'feed':
|
||||
|
|
21
utils/backups/backup_psql.py
Normal file
21
utils/backups/backup_psql.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
import s3
|
||||
from django.conf import settings
|
||||
|
||||
db_name = 'newsblur'
|
||||
db_pass = settings.DATABASES['default']['PASSWORD']
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
NEWSBLUR_DIR = ''.join([CURRENT_DIR, '../../'])
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
||||
os.environ['PGPASSWORD'] = db_pass
|
||||
sys.path.insert(0, NEWSBLUR_DIR)
|
||||
|
||||
filename = 'backup_postgresql_%s.sql.gz' % time.strftime('%Y-%m-%d-%H-%M')
|
||||
cmd = 'pg_dump -U newsblur -Fc %s > %s' % (db_name, filename)
|
||||
os.system(cmd)
|
||||
|
||||
s3.save_file_in_s3(filename)
|
||||
os.remove(filename)
|
Loading…
Add table
Reference in a new issue