[tracker/tracker-control-with-backup-and-restore] tracker-control: Add --backup and --restore support



commit a4771db52bb52aef368c1ed17e2ef75b2d15b0cb
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Apr 28 17:16:24 2011 +0100

    tracker-control: Add --backup and --restore support
    
    These command line options provide an easy way to use the d-bus interfaces

 docs/manpages/tracker-control.1               |   12 +++
 src/tracker-control/tracker-control-general.c |  128 ++++++++++++++++++++++++-
 2 files changed, 139 insertions(+), 1 deletions(-)
---
diff --git a/docs/manpages/tracker-control.1 b/docs/manpages/tracker-control.1
index 978e1c1..5ce9aee 100644
--- a/docs/manpages/tracker-control.1
+++ b/docs/manpages/tracker-control.1
@@ -84,6 +84,18 @@ configuration files.
 .B \-s, \-\-start
 Starts all miners. This indirectly starts tracker-store too because it
 is needed for miners to operate properly.
+.TP
+.B \-b, \-\-backup=PATH
+Begins backing up the Tracker databases to the
+.B PATH
+given.
+.TP
+.B \-o, \-\-restore=PATH
+Begins restoring a previous backup (see
+.B \-\-backup
+) to the Tracker databases. The
+.B PATH
+points to the location of the backup.
 
 .SH STATUS OPTIONS
 .TP
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index f15ed2e..a8756e3 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -52,6 +52,8 @@ static gboolean hard_reset;
 static gboolean soft_reset;
 static gboolean remove_config;
 static gboolean start;
+static gchar *backup;
+static gchar *restore;
 
 #define GENERAL_OPTIONS_ENABLED() \
 	(list_processes || \
@@ -60,7 +62,9 @@ static gboolean start;
 	 hard_reset || \
 	 soft_reset || \
 	 remove_config || \
-	 start)
+	 start || \
+	 backup || \
+	 restore)
 
 static gboolean term_option_arg_func (const gchar  *option_value,
                                       const gchar  *value,
@@ -88,6 +92,12 @@ static GOptionEntry entries[] = {
 	{ "start", 's', 0, G_OPTION_ARG_NONE, &start,
 	  N_("Starts miners (which indirectly starts tracker-store too)"),
 	  NULL },
+	{ "backup", 'b', 0, G_OPTION_ARG_STRING, &backup,
+	  N_("Backup databases to the location provided"),
+	  N_("PATH") },
+	{ "restore", 'o', 0, G_OPTION_ARG_STRING, &restore,
+	  N_("Restore databases from the location provided"),
+	  N_("PATH") },
 	{ NULL }
 };
 
@@ -539,6 +549,122 @@ tracker_control_general_run (void)
 		g_object_unref (manager);
 	}
 
+	if (backup) {
+		GDBusConnection *connection;
+		GDBusProxy *proxy;
+		GError *error = NULL;
+		GVariant *v;
+
+		g_print ("%s\n", _("Backing up database"));
+		g_print ("  %s\n", backup);
+
+		connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+		if (!connection) {
+			g_critical ("Could not connect to the D-Bus session bus, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		proxy = g_dbus_proxy_new_sync (connection,
+		                               G_DBUS_PROXY_FLAGS_NONE,
+		                               NULL,
+		                               "org.freedesktop.Tracker1",
+		                               "/org/freedesktop/Tracker1/Backup",
+		                               "org.freedesktop.Tracker1.Backup",
+		                               NULL,
+		                               &error);
+
+		if (error) {
+			g_critical ("Could not create proxy on the D-Bus session bus, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		v = g_dbus_proxy_call_sync (proxy,
+		                            "Save",
+		                            g_variant_new ("(s)", backup),
+		                            G_DBUS_CALL_FLAGS_NONE,
+		                            -1,
+		                            NULL,
+		                            &error);
+
+		if (proxy) {
+			g_object_unref (proxy);
+		}
+
+		if (error) {
+			g_critical ("Could not backup database, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		if (v) {
+			g_variant_unref (v);
+		}
+	}
+
+	if (restore) {
+		GDBusConnection *connection;
+		GDBusProxy *proxy;
+		GError *error = NULL;
+		GVariant *v;
+
+		g_print ("%s\n", _("Restoring database from backup"));
+		g_print ("  %s\n", restore);
+
+		connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+		if (!connection) {
+			g_critical ("Could not connect to the D-Bus session bus, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		proxy = g_dbus_proxy_new_sync (connection,
+		                               G_DBUS_PROXY_FLAGS_NONE,
+		                               NULL,
+		                               "org.freedesktop.Tracker1",
+		                               "/org/freedesktop/Tracker1/Backup",
+		                               "org.freedesktop.Tracker1.Backup",
+		                               NULL,
+		                               &error);
+
+		if (error) {
+			g_critical ("Could not create proxy on the D-Bus session bus, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		v = g_dbus_proxy_call_sync (proxy,
+		                            "Restore",
+		                            g_variant_new ("(s)", restore),
+		                            G_DBUS_CALL_FLAGS_NONE,
+		                            -1,
+		                            NULL,
+		                            &error);
+
+		if (proxy) {
+			g_object_unref (proxy);
+		}
+
+		if (error) {
+			g_critical ("Could not restore database, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			return EXIT_FAILURE;
+		}
+
+		if (v) {
+			g_variant_unref (v);
+		}
+	}
+
 	return EXIT_SUCCESS;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]