[glom/feature_backup2] PostgreSQL backups: Archive the directory in a .tar.gz..



commit c197c88aded0f438cc7417806e2ad3c49aa97a05
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Jul 7 11:29:59 2010 +0200

    PostgreSQL backups: Archive the directory in a .tar.gz..
    
    * configure.ac: Check for the tar and gzip executables.
    * glom/application.cc: on_menu_developer_export_backup(): Use tar
        via the command line, to put it all in a .tar.gz, so it is self-contained.

 ChangeLog           |    8 ++++++++
 configure.ac        |   12 ++++++++++++
 glom/application.cc |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 686721d..e1fdb33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-07-07  Murray Cumming  <murrayc murrayc com>
 
+	PostgreSQL backups: Archive the directory in a .tar.gz..
+
+	* configure.ac: Check for the tar and gzip executables.
+	* glom/application.cc: on_menu_developer_export_backup(): Use tar
+    via the command line, to put it all in a .tar.gz, so it is self-contained.
+
+2010-07-07  Murray Cumming  <murrayc murrayc com>
+
 	PostgreSQL backups: Use .pgpass.
 
 	* glom/libglom/connectionpool_backends/postgres.[h|cc]:
diff --git a/configure.ac b/configure.ac
index 159a364..97acd37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -260,6 +260,18 @@ AS_IF([test "x$ENABLE_DOCUMENTATION" != xno],
      [],
      [AC_MSG_ERROR([The documentation build is enabled, but the sphinx-build tool could not be found.])])])
 
+# Check for tar and gzip (used by tar via -z) because we use these when creating backups.
+# TODO: This lets us provide a path via a configure option, but we just use Glib::find_program_in_path(), ignoring that.
+AC_CHECK_PROG([GLOM_TAR], [tar], [yes], [no])
+if test "$GLOM_TAR" = no ; then
+	AC_MSG_ERROR([tar not found. Glom needs this to create backup files.])
+fi
+
+AC_CHECK_PROG([GLOM_GZIP], [gzip], [yes], [no])
+if test "$GLOM_GZIP" = no ; then
+	AC_MSG_ERROR([gzip not found. Glom needs this to create backup files.])
+fi
+
 AC_CONFIG_FILES([Makefile
                  docs/user-guide/Makefile
                  po/Makefile.in
diff --git a/glom/application.cc b/glom/application.cc
index fc434ae..ede494b 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -36,6 +36,7 @@
 #include <glom/glom_privs.h>
 #include <glom/python_embed/python_ui_callbacks.h>
 #include <glom/python_embed/glom_python.h>
+#include <libglom/spawn_with_feedback.h>
 
 #include <cstdio>
 #include <memory> //For std::auto_ptr<>
@@ -2612,6 +2613,54 @@ void Application::on_menu_developer_export_backup()
     }
   }
 
+  //Compress the backup in a .tar.gz, so it is slightly more safe from changes:
+  const std::string path_tar = Glib::find_program_in_path("tar");
+  if(path_tar.empty())
+  {
+    std::cerr << G_STRFUNC << ": The tar executable could not be found." << std::endl;
+    saved = false;
+  }
+  else
+  {
+    Glib::RefPtr<const Gio::File> gio_file = Gio::File::create_for_path(path_dir);
+    const std::string basename = gio_file->get_basename();
+    Glib::RefPtr<const Gio::File> gio_file_parent = gio_file->get_parent();
+    const std::string parent_dir = gio_file_parent->get_path();
+    if(parent_dir.empty() || basename.empty())
+    {
+      std::cerr << G_STRFUNC << "parent_dir or basename are empty." << std::endl;
+      saved = false;
+    }
+    else
+    {
+      //TODO: Find some way to do this without using the command-line,
+      //which feels fragile:
+      const std::string command_tar = "\"" + path_tar + "\"" +
+        " --force-local --no-wildcards" + //Avoid side-effects of special characters.
+        " --remove-files" +
+        " -czf"
+        " \"" + path_dir + ".tar.gz\"" +
+        " --directory \"" + parent_dir + "\"" + //This must be right before the mention of the file name:
+        " \"" + basename + "\"";
+
+      std::cout << "DEBUG: command_tar=" << command_tar << std::endl;
+
+      saved = Glom::Spawn::execute_command_line_and_wait(command_tar,
+        sigc::mem_fun(*this, &Application::on_connection_save_backup_progress));
+
+      if(saved)
+      {
+
+      }
+
+      if(m_dialog_progess_save_backup)
+      {
+        delete m_dialog_progess_save_backup;
+        m_dialog_progess_save_backup = 0;
+      }
+    }
+  }
+
   if(!saved)
     ui_warning(_("Export Backup failed."), _("There was an error while exporting the backup."));
 }



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