handle swap partitions better during import/export import_export_swap
authorGalen Charlton <gmc@esilibrary.com>
Thu, 8 Aug 2013 20:01:45 +0000 (16:01 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 8 Aug 2013 20:01:45 +0000 (16:01 -0400)
Changes the export file format so that the first
line indicates whether the device being exported or
imported is a swap device or an ext* filesystem.

If it's a swap device, it's just recreated on import;
there's no reason to retain its contents.

WARNING: This makes previous gnt-backup filesystem exports
incompatible unless they are modified so that their first
line contains "ext3" or "ext4".

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

export
import

diff --git a/export b/export
index 46aa74c..703d4d6 100755 (executable)
--- a/export
+++ b/export
@@ -29,6 +29,15 @@ if [ ! -b $blockdev ]; then
   CLEANUP+=("losetup -d $blockdev")
 fi
 
+# There's no reason to try to export a swap device's
+# contents, we just want to recreate it.
+if vol_type=$($VOL_TYPE $blockdev); then
+  if [ "$vol_type" = "swap" ]; then
+    echo swap
+    exit 0
+  fi
+fi
+
 if [ "$PARTITION_STYLE" = "none" ]; then
   filesystem_dev=$blockdev
 elif [ "$PARTITION_STYLE" = "msdos" ]; then
@@ -42,6 +51,7 @@ fi
 vol_type=$($VOL_TYPE $filesystem_dev)
 
 if [ "${vol_type:0:3}" = "ext" ]; then
+  echo $vol_type
   dump -0 -q -f - "$filesystem_dev"
 else
   echo "Can't dump partition of type ${vol_type}!" >&2
diff --git a/import b/import
index 2d9b58e..da482ba 100755 (executable)
--- a/import
+++ b/import
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 # Copyright (C) 2007, 2008, 2009 Google Inc.
+# Portions Copyright 2013 Equinox Software, Inc.
 #
 # 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
@@ -29,6 +30,14 @@ if [ ! -b $blockdev ]; then
   CLEANUP+=("losetup -d $blockdev")
 fi
 
+# First line in the dump contains the partion and/or 
+# filesystem type.
+read -r export_type
+if [ "$export_type" = "swap" ]; then
+  mkswap -f $blockdev
+  exit 0
+fi
+
 if [ "$PARTITION_STYLE" = "none" ]; then
   filesystem_dev=$blockdev
 elif [ "$PARTITION_STYLE" = "msdos" ]; then