Skip to content

Commit

Permalink
Merge pull request #8 from adamjmcgrath/move-backups
Browse files Browse the repository at this point in the history
Move and organise backups folder
  • Loading branch information
adamjmcgrath committed Aug 12, 2015
2 parents 22eef69 + 57c2e09 commit dc744a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python:
env:
global:
- secure: KTWs8jE9COxyuULlAiynxrI61wKfZhz56B99zT75e4tdcCSGRIIWut8Skm1thAUSQsEymXhvhhmgND3qbjChyw90F/hAiA8xgo/QxpESvI48AXi9CLPfB9kyaf9SPqXokKxj0yYqCCYLLfmCu/glO66S69+5iQbwn8M+9WHdeHwYffJrFJonUt/E0HAuaNdmJIDCd3nuAp7Ol7JAuUsg8971SoeDqk+wBPNzN4UWYtpWGvxUas51w7YjIPwG7cr6C3XvP/G1x2YPU6yP0gQBtgKt3X3+W6FJqO1GZaiQ1iTK+nRhaU1SecjmkHJJKQjQDX+0CLVWW5Y98SrbtKYht/Ez3/3GG4NyHTtmBZ67F4cC3ikdTRDp3ixTAoay7M4osIgvkdNsCeiYGz8dXvIbOsh+bebCPHwYfdsVk0656XS3V2G5EnXMhqaOzDqdwdCMCUR/LUm4GOmZ2BqNAQT/CnsWugE7BZwyN9I8S1bVMfU0a4soXNAlXbr6Kzr01cdX7Po43y7GOe4QgQHMJuNrFzbJ24IT/OOKJKkgRRfUQoX3LQHH++EHUnKpeTDrT72MRp095jiRW5gjUVjidTtYG0YruZ4PFv66ICKHEmVEm57ATxjupea/goESWslp1/Vj2XV3mKhVcGwJ52WHV2czh8EEu/G16XZMHqwFDjIOg6c=
- APPENGINE_SDK=google_appengine_1.9.21
- APPENGINE_SDK=google_appengine_1.9.24

cache:
directories:
Expand Down
3 changes: 1 addition & 2 deletions src/cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ cron:
schedule: every monday 05:00

- description: weekly backup
url: /_ah/datastore_admin/backup.create?kind=Clue&kind=Question&kind=Season&kind=User&kind=UserQuestion&kind=UserSeason&kind=UserToken&kind=League&kind=LeagueUser&filesystem=gs&gs_bucket_name=ffcapp.appspot.com
url: /tasks/backup
schedule: every saturday 01:00
target: ah-builtin-python-bundle
timezone: Europe/London
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'tasks-cleananonusers'),
webapp2.Route(r'/tasks/cleanupusertokens', tasks.CleanUpUserTokens,
'tasks-cleanupusertokens'),
webapp2.Route(r'/tasks/backup', tasks.ScheduledBackup, 'tasks-backup'),

# Api.
webapp2.Route(r'/api/question/<:.+>', question.Question, 'api-question'),
Expand Down
3 changes: 3 additions & 0 deletions src/queue.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
queue:
- name: pose
rate: 100/s
- name: backup-builtin-queue
rate: 30/s
target: ah-builtin-python-bundle
28 changes: 28 additions & 0 deletions src/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@
import datetime
import logging

from google.appengine.api import taskqueue
from google.appengine.ext import deferred, blobstore, ndb
from webapp2_extras.appengine.auth.models import UserToken

import baserequesthandler
import models

BATCH_SIZE = 100
BACKUP_ENTITIES = [
'Clue',
'Question',
'Season',
'User',
'UserQuestion',
'UserSeason',
'UserToken',
'League',
'LeagueUser',
]


def delete_user(user_id, anonymous=False):
Expand Down Expand Up @@ -93,3 +105,19 @@ def get(self):
else:
break


class ScheduledBackup(baserequesthandler.RequestHandler):

def get(self):
backup_folder = datetime.now().strftime('%y-%m-%d')
bucket_name = 'ffcapp.appspot.com/backups/%s' % backup_folder
params = {
'filesystem' : 'gs',
'gs_bucket_name': bucket_name,
'kind' : BACKUP_ENTITIES
}

url = '/_ah/datastore_admin/backup.create'

logging.info('Backing up %s to: %s' % (BACKUP_ENTITIES, bucket_name))
taskqueue.add(url=url, params=params, queue_name='backup-builtin-queue')

0 comments on commit dc744a5

Please sign in to comment.