Penso che tu abbia identificato praticamente tutte le tue scelte.
- Fidati di Google per non perdere i tuoi dati e spero che non accidentalmente istruisca loro a distruggerlo.
- Eseguire backup completi con
download_data
, forse meno frequentemente di una volta a notte se è eccessivamente costoso.
- Rotola la tua soluzione di backup incrementale.
L'opzione 3 è in realtà un'idea interessante. Avresti bisogno di un timestamp di modifica su tutte le entità, e non cattureresti entità cancellate, ma altrimenti è molto fattibile con remote_api e cursori.
Edit:
Ecco un semplice downloader incrementale per l'uso con remote_api. Di nuovo, le avvertenze sono che non noterà entità cancellate e presuppone che tutte le entità memorizzino l'ultima modifica in una proprietà denominata updated_at. Usalo a tuo rischio e pericolo.
import os
import hashlib
import gzip
from google.appengine.api import app_identity
from google.appengine.ext.db.metadata import Kind
from google.appengine.api.datastore import Query
from google.appengine.datastore.datastore_query import Cursor
INDEX = 'updated_at'
BATCH = 50
DEPTH = 3
path = ['backups', app_identity.get_application_id()]
for kind in Kind.all():
kind = kind.kind_name
if kind.startswith('__'):
continue
while True:
print 'Fetching %d %s entities' % (BATCH, kind)
path.extend([kind, 'cursor.txt'])
try:
cursor = open(os.path.join(*path)).read()
cursor = Cursor.from_websafe_string(cursor)
except IOError:
cursor = None
path.pop()
query = Query(kind, cursor=cursor)
query.Order(INDEX)
entities = query.Get(BATCH)
for entity in entities:
hash = hashlib.sha1(str(entity.key())).hexdigest()
for i in range(DEPTH):
path.append(hash[i])
try:
os.makedirs(os.path.join(*path))
except OSError:
pass
path.append('%s.xml.gz' % entity.key())
print 'Writing', os.path.join(*path)
file = gzip.open(os.path.join(*path), 'wb')
file.write(entity.ToXml())
file.close()
path = path[:-1-DEPTH]
if entities:
path.append('cursor.txt')
file = open(os.path.join(*path), 'w')
file.write(query.GetCursor().to_websafe_string())
file.close()
path.pop()
path.pop()
if len(entities) < BATCH:
break
fonte
2011-11-10 01:00:33
Sulla tua ultima domanda, riporta questo errore: [776] (http://code.google.com/p/googleappengine/issues/detail?id=776) –