Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/journal-restore-volume
blob: baf270f3c2dbdbf18b488535f776db5ef61a35e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# Copyright (C) 2010, Paraguay Educa <tecnologia@paraguayeduca.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
import sys
import shutil
import logging
import subprocess

from jarabe.model import processmanagement

from sugar import env
#from sugar.datastore import datastore

backup_identifier = sys.argv[2]
volume_path = sys.argv[1]

if len(sys.argv) != 3:
    print 'Usage: %s <volume_path> <backup_identifier>' % sys.argv[0]
    exit(1)

logging.debug('Restore started')

journal_path = os.path.join(env.get_profile_path(), 'datastore')
backup_path = os.path.join(volume_path, 'backup', backup_identifier, 'datastore.tar.gz')

if not os.path.exists(backup_path):
    logging.error('Could not find backup file %s', backup_path)
    exit(processmanagement.BACKUP_OF_CURRENT_SYSTEM_NOT_FOUND)

#datastore.freeze()
subprocess.call(['pkill', '-9', '-f', 'python.*datastore-service'])

result = 0
try:
    if os.path.exists(journal_path):
        shutil.rmtree(journal_path)

    subprocess.check_call(['tar', '-C', env.get_profile_path(), '-xzf', backup_path])

except Exception, e:
    logging.error('Restore failed: %s', str(e))
    result = 1

try:
  shutil.rmtree(os.path.join(journal_path, 'index'))
  os.remove(os.path.join(journal_path, 'index_updated'))
  os.remove(os.path.join(journal_path, 'version'))
except:
  logging.debug('Restore has no index files')

#datastore.thaw()

logging.debug('Restore finished')
exit(result)