167.2.1
by Sergio Schvezov
Backup and restore when flashing ubuntu image based upgrade. |
1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
2 |
# Copyright (C) 2013 Canonical Ltd.
|
|
3 |
# Author: Sergio Schvezov <sergio.schvezov@canonical.com>
|
|
4 |
||
5 |
# This program is free software: you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU General Public License as published by
|
|
7 |
# the Free Software Foundation; version 3 of the License.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
||
17 |
import logging |
|
18 |
import tempfile |
|
19 |
||
20 |
log = logging.getLogger() |
|
21 |
||
22 |
||
23 |
def backup(adb, backup_file=tempfile.mkstemp()[1]): |
|
24 |
adb.shell('tar -czpf /tmp/backup.tar.gz ' |
|
25 |
'/home/phablet '
|
|
26 |
'/etc/NetworkManager/system-connections') |
|
27 |
log.info('Saving backup to %s' % backup_file) |
|
28 |
adb.pull('/tmp/backup.tar.gz', backup_file) |
|
29 |
return backup_file |
|
30 |
||
31 |
||
32 |
def restore(adb, backup_file): |
|
33 |
adb.push(backup_file, '/tmp/backup.tar.gz') |
|
34 |
log.info('Restoring from %s' % backup_file) |
|
35 |
adb.shell('tar -xzpf /tmp/backup.tar.gz -C /') |
|
36 |
adb.reboot() |