[Sugar-devel] [sucrose-0.84] Enhancements to dsd's restore and backup script

Martin Abente mabente at paraguayeduca.org
Fri May 21 15:31:13 EDT 2010


The current script was not able to run on non-xo machines, plus a few
improvements to the scripts, i.e makefiles and copyright amends.

Signed-off-by: Martin Abente <mabente at paraguayeduca.org>
---
 bin/Makefile.am                       |    4 +-
 bin/journal-backup-volume             |   63 +++++++++++++++++++++++++++
 bin/journal-restore-volume            |   77 +++++++++++++++++++++++++++++++++
 src/jarabe/model/processmanagement.py |    5 ++-
 4 files changed, 147 insertions(+), 2 deletions(-)
 create mode 100755 bin/journal-backup-volume
 create mode 100755 bin/journal-restore-volume

diff --git a/bin/Makefile.am b/bin/Makefile.am
index 05a9215..cdb23ee 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -5,7 +5,9 @@ python_scripts =		\
 	sugar-install-bundle	\
 	sugar-launch		\
 	sugar-session		\
-	sugar-ui-check
+	sugar-ui-check \
+	journal-backup-volume \
+  journal-restore-volume
 
 bin_SCRIPTS = 			\
 	sugar			\
diff --git a/bin/journal-backup-volume b/bin/journal-backup-volume
new file mode 100755
index 0000000..fd25585
--- /dev/null
+++ b/bin/journal-backup-volume
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# Copyright (C) 2010 Plan Ceibal
+# Copyright (C) 2010 Paraguay Educa
+#
+# 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/>.
+#
+# Contact information: comunidad at plan.ceibal.edu.uy
+# Plan Ceibal http://www.ceibal.edu.uy
+
+# This shell script makes a sugar journal backup
+
+if [ -z "$1" ]; then
+	echo "Usage: $0 <backup destination>" >&2
+	exit 1 
+fi
+
+function validate_path() {
+	if [ ! -d "$1" ]; then
+		echo "No such file $1" >&2
+		exit 1
+	fi
+}
+
+SERIAL="$LOGNAME"
+[ -f /ofw/serial-number ] && SERIAL=$(cat /ofw/serial-number)
+DATASTORE="$HOME/.sugar/default/datastore/"
+validate_path $DATASTORE
+
+DEST_PATH=$1
+validate_path "$DEST_PATH"
+
+PATH_FILE="$DEST_PATH/backup/$SERIAL"
+
+pkill -f -x "python /usr/bin/datastore-service"
+sleep 1
+
+echo -n "Starting"
+mkdir -p $PATH_FILE
+
+echo -n "Switching to the working directory"
+cd $DATASTORE
+tar -zcf "$PATH_FILE"/datastore.tar.gz .
+if [ $? -ne 0 ]; then
+  echo "Error while packing datastore"
+  exit 1
+fi
+
+echo -n "Restart"
+sleep 2
+pkill -f -x "python /usr/bin/sugar-session"
+
diff --git a/bin/journal-restore-volume b/bin/journal-restore-volume
new file mode 100755
index 0000000..ba5120d
--- /dev/null
+++ b/bin/journal-restore-volume
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# Copyright (C) 2010 Plan Ceibal
+# Copyright (C) 2010 Paraguay Educa
+#
+# 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/>.
+#
+# Contact information: comunidad at plan.ceibal.edu.uy
+# Plan Ceibal http://www.ceibal.edu.uy
+
+# This script restore sugar journal from backup
+
+if [ -z "$1" ]; then
+	echo "Usage: $0 <backup origin>" >&2
+	exit 1 
+fi
+
+function controlError {
+	if [[ $? != 0 ]]; then
+		echo "$1" >&2
+		exit 1
+	fi
+}
+
+function validate_path() {
+	if !(test -e "$1"); then
+		echo "No such file $1" >&2;
+		exit 1 
+	fi
+}
+
+SERIAL="$LOGNAME"
+[ -f /ofw/serial-number ] && SERIAL=$(cat /ofw/serial-number)
+DATASTORE="$HOME/.sugar/default/datastore/"
+validate_path $DATASTORE
+
+SRC_PATH=$1
+validate_path $SRC_PATH
+
+PATH_FILE=$SRC_PATH/backup/$SERIAL/datastore.tar.gz
+validate_path $PATH_FILE
+
+echo -n "Starting"
+pkill -f -x "python /usr/bin/datastore-service"
+sleep 1
+
+echo -n "Moving to the working directory"
+cp $PATH_FILE $DATASTORE
+controlError "Error while copying the files"
+cd $DATASTORE
+
+rm -rf "$DATASTORE"store/*
+controlError ""
+
+echo -n "Unpacking"
+tar -xvzf $PATH_FILE
+controlError "Error while unpacking "$PATH_FILE
+rm "$DATASTORE"datastore.tar.gz
+controlError "Error while deleting temporal files"
+
+
+echo -n "Restarting"
+sleep 2
+
+pkill -f -x "python /usr/bin/sugar-session"
+
diff --git a/src/jarabe/model/processmanagement.py b/src/jarabe/model/processmanagement.py
index 102bdca..9c7ccf0 100644
--- a/src/jarabe/model/processmanagement.py
+++ b/src/jarabe/model/processmanagement.py
@@ -1,5 +1,5 @@
-# Copyright (C) 2010, Plan Ceibal <comunidad at plan.ceibal.edu.uy>
 # Copyright (C) 2010 Paraguay Educa, Martin Abente, Bernie Innocenti
+# Copyright (C) 2010, Plan Ceibal <comunidad at plan.ceibal.edu.uy>
 #
 # 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
@@ -14,6 +14,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# Contact information mabente at paraguayeduca.org
+# Paraguay Educa http://www.paraguayeduca.org
 
 import os
 import gobject
-- 
1.6.0.4



More information about the Sugar-devel mailing list