From sugar-devel-bounces@lists.sugarlabs.org Fri May 21 21:42:20 2010
Return-Path: <sugar-devel-bounces@lists.sugarlabs.org>
X-Original-To: bernie@codewiz.org
Delivered-To: bernie@trinity.develer.com
Received: from solarsail.media.mit.edu (solarsail.media.mit.edu
 [18.85.2.155]) by trinity.develer.com (Postfix) with ESMTPS id 3928B1D60BB
 for <bernie@codewiz.org>; Fri, 21 May 2010 21:42:20 +0200 (CEST)
X-Virus-Status: Clean
X-Virus-Scanned: clamav-milter 0.95.2 at trinity.develer.com
Received: from solarsail.media.mit.edu (localhost [127.0.0.1]) by
 solarsail.media.mit.edu (Postfix) with ESMTP id 3BE817BC73E; Fri, 21 May
 2010 15:42:19 -0400 (EDT)
Received: from buho.paraguayeduca.org (mail.paraguayeduca.org
 [190.104.152.113]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256
 bits)) (No client certificate requested) by solarsail.media.mit.edu
 (Postfix) with ESMTPS id 350837BC738 for <sugar-devel@lists.sugarlabs.org>;
 Fri, 21 May 2010 15:42:15 -0400 (EDT)
Received: (qmail 30966 invoked by uid 508); 21 May 2010 15:52:33 -0400
Received: from unknown (HELO localhost.localdomain) (192.168.0.233) by
 buho.paraguayeduca.org with SMTP; 21 May 2010 15:52:33 -0400
From: Martin Abente <mabente@paraguayeduca.org>
To: earias@plan.ceibal.edu.uy
Date: Fri, 21 May 2010 15:42:09 -0400
Message-Id: <1274470929-6800-1-git-send-email-mabente@paraguayeduca.org>
X-Mailer: git-send-email 1.6.0.4
In-Reply-To: <1274470273-6380-2-git-send-email-mabente@paraguayeduca.org>
References: <1274470273-6380-2-git-send-email-mabente@paraguayeduca.org>
Organization: Paraguay Educa
Cc: sugar-devel@lists.sugarlabs.org, bernie@codewiz.org, Martin Abente
 <mabente@paraguayeduca.org>
Subject: [Sugar-devel] [PATCH] Enhancements to dsd's restore and backup
 script (v2)
X-BeenThere: sugar-devel@lists.sugarlabs.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: "Discussion of Sugar development and other technical matters."
 <sugar-devel.lists.sugarlabs.org>
List-Unsubscribe: <http://lists.sugarlabs.org/listinfo/sugar-devel>,
 <mailto:sugar-devel-request@lists.sugarlabs.org?subject=unsubscribe>
List-Archive: <http://lists.sugarlabs.org/archive/sugar-devel>
List-Post: <mailto:sugar-devel@lists.sugarlabs.org>
List-Help: <mailto:sugar-devel-request@lists.sugarlabs.org?subject=help>
List-Subscribe: <http://lists.sugarlabs.org/listinfo/sugar-devel>,
 <mailto:sugar-devel-request@lists.sugarlabs.org?subject=subscribe>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Sender: sugar-devel-bounces@lists.sugarlabs.org
Errors-To: sugar-devel-bounces@lists.sugarlabs.org
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY
 autolearn=unavailable version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
 trinity.develer.com
X-Evolution-Source: imap://bernie@imap.develer.com/
Content-Transfer-Encoding: 8bit

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.

This version fixes the sugar/bin makefile

Signed-off-by: Martin Abente <mabente@paraguayeduca.org>
---
 bin/Makefile.am                       |    8 +++-
 bin/journal-backup-volume             |   63 +++++++++++++++++++++++++++
 bin/journal-restore-volume            |   77 +++++++++++++++++++++++++++++++++
 src/jarabe/model/processmanagement.py |    5 ++-
 4 files changed, 150 insertions(+), 3 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..dc151af 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -5,10 +5,14 @@ python_scripts =		\
 	sugar-install-bundle	\
 	sugar-launch		\
 	sugar-session		\
-	sugar-ui-check
+	sugar-ui-check \
+	#
 
 bin_SCRIPTS = 			\
 	sugar			\
-	$(python_scripts)
+	journal-backup-volume \
+	journal-restore-volume \
+	$(python_scripts) \
+	#
 
 EXTRA_DIST = $(python_scripts) sugar.in
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@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@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@plan.ceibal.edu.uy>
 # Copyright (C) 2010 Paraguay Educa, Martin Abente, Bernie Innocenti
+# Copyright (C) 2010, Plan Ceibal <comunidad@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@paraguayeduca.org
+# Paraguay Educa http://www.paraguayeduca.org
 
 import os
 import gobject
-- 
1.6.0.4

_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

