[PATCH] Add journal-{backup,backup-list,restore}

Bernie Innocenti bernie at codewiz.org
Fri Apr 9 16:40:12 EDT 2010


Signed-off-by: Bernie Innocenti <bernie at codewiz.org>
---
 Makefile.build             |    3 +++
 client/journal-backup      |   43 +++++++++++++++++++++++++++++++++++++++++++
 client/journal-backup-list |   38 ++++++++++++++++++++++++++++++++++++++
 client/journal-restore     |   30 ++++++++++++++++++++++++++++++
 ds-backup.spec.in          |    8 +++++++-
 5 files changed, 121 insertions(+), 1 deletions(-)
 create mode 100644 client/journal-backup
 create mode 100644 client/journal-backup-list
 create mode 100644 client/journal-restore

diff --git a/Makefile.build b/Makefile.build
index 2e1712e..f6cd00f 100644
--- a/Makefile.build
+++ b/Makefile.build
@@ -5,6 +5,9 @@ install-client:
 	install -D -d $(DESTDIR)/usr/bin
 	install -D client/ds-backup.py $(DESTDIR)/usr/bin/
 	install -D client/ds-backup.sh $(DESTDIR)/usr/bin/
+	install -D client/journal-backup      $(DESTDIR)/usr/bin/
+	install -D client/journal-backup-list $(DESTDIR)/usr/bin/
+	install -D client/journal-restore     $(DESTDIR)/usr/bin/
 	install -D -d $(DESTDIR)/etc
 	install -D -m 644 client/cron-ds-backup.conf $(DESTDIR)/etc/cron.d/ds-backup
 
diff --git a/client/journal-backup b/client/journal-backup
new file mode 100644
index 0000000..54ca743
--- /dev/null
+++ b/client/journal-backup
@@ -0,0 +1,43 @@
+#!/bin/bash
+# Copyright (C) 2009 Daniel Drake <dsd at laptop.org>
+# Copyright (C) 2010 Paraguay Educa <http://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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US 
+
+echo "Starting"
+
+# make the lock dir if needed
+# we will keep the (empty) file around
+if [ ! -d ~/.sugar/default/lock ]; then
+	mkdir ~/.sugar/default/lock || exit 1;
+fi
+LOCKFILE=~/.sugar/default/lock/ds-backup.run
+echo "Locking"
+
+# this fails when (this script is) copied to a usb stick 
+#flock -n $LOCKFILE `dirname $0 `/ds-backup.py
+#flock -n $LOCKFILE /usr/bin/ds-backup.py
+echo "Backing up"
+python /usr/bin/ds-backup.py
+
+EXITCODE=$?
+
+if [[ ${EXITCODE} != 0 ]]; then
+        echo "Sorry, it failed";
+        exit -1;
+fi
+
+echo "Great, it is done"
+exit 0
diff --git a/client/journal-backup-list b/client/journal-backup-list
new file mode 100644
index 0000000..da71ce7
--- /dev/null
+++ b/client/journal-backup-list
@@ -0,0 +1,38 @@
+#!/bin/bash
+# Copyright (C) 2009 Daniel Drake <dsd at laptop.org>
+# Copyright (C) 2010 Paraguay Educa <http://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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US
+
+sn=$(</ofw/mfg-data/SN)
+output=$(echo "ls -1" | sftp -F /dev/null -oPasswordAuthentication=no -oStrictHostKeyChecking=no -oUser=${sn} -oIdentityFile=/home/olpc/.sugar/default/owner.key schoolserver)
+
+EXITCODE=$?
+
+if [[ $? != 0 ]]; then
+	exit ${EXITCODE}
+fi
+
+IFS=""
+
+for line in ${output}; do
+	if [[ ${line:0:10} != "datastore-" || ${line} == "datastore-latest" ]]; then	
+		continue
+	fi
+	echo " - ${line:10}"
+done
+
+exit ${EXITCODE}
+
diff --git a/client/journal-restore b/client/journal-restore
new file mode 100644
index 0000000..c69ac44
--- /dev/null
+++ b/client/journal-restore
@@ -0,0 +1,30 @@
+#!/bin/bash
+# Copyright (C) 2009 Daniel Drake <dsd at laptop.org>
+# Copyright (C) 2010 Paraguay Educa <http://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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US
+
+to_restore=${1:-current}
+
+pkill -f -x "python /usr/bin/datastore-service"
+
+sn=$(</ofw/mfg-data/SN)
+sshcmd="ssh -F /dev/null -o 'PasswordAuthentication no' -o 'StrictHostKeyChecking no' -i /home/olpc/.sugar/default/owner.key -l ${sn}"
+rsync -z -rlt --delete-before -e "${sshcmd}" --progress \
+	"schoolserver:datastore-${to_restore}/" \
+	"/home/olpc/.sugar/default/datastore/"
+
+exit $?
+
diff --git a/ds-backup.spec.in b/ds-backup.spec.in
index fde1f60..5a94837 100644
--- a/ds-backup.spec.in
+++ b/ds-backup.spec.in
@@ -31,6 +31,9 @@ Requires:       sugar-datastore
 Requires:       sugar
 Requires:       vixie-cron
 
+# For /usr/bin/flock
+Requires:	util-linux-ng
+
 %package server
 
 Summary:        OLPC DS backup & restore server
@@ -78,6 +81,9 @@ chkconfig --level 345 incrond on
 %config %{_sysconfdir}/cron.d/ds-backup
 %{_bindir}/ds-backup.py
 %{_bindir}/ds-backup.sh
+%{_bindir}/journal-backup
+%{_bindir}/journal-backup-list
+%{_bindir}/journal-restore
 
 %files server
 %defattr(-,root,root,-)
@@ -90,7 +96,7 @@ chkconfig --level 345 incrond on
 %{_bindir}/ds-postprocess.py
 %{_bindir}/ds-cleanup.sh
 %{_bindir}/ds-cleanup.py
-/var/www/ds-backup/backup-available.py
+%{_var}/www/ds-backup/backup-available.py*
 %attr(700, apache, apache) %dir %{_localstatedir}/lib/ds-backup/recentclients
 %attr(777, nobody, nobody) %dir %{_localstatedir}/lib/ds-backup/completion
 
-- 
1.7.0.1


--=-waKH9YHbN02ylDPMbF6M--



More information about the SoaS mailing list