KVM snapshots backUp path in 22 had entire path, instead of relative path. Fix 
modifies the path to make it relative during upgrade


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a23f151d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a23f151d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a23f151d

Branch: refs/heads/vmware-storage-motion
Commit: a23f151df57a16457587207e612b3f26911806e6
Parents: 47a562a
Author: Kishan Kavala <kis...@cloud.com>
Authored: Fri May 24 14:41:17 2013 +0530
Committer: Kishan Kavala <kis...@cloud.com>
Committed: Fri May 24 14:41:28 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |   40 +++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a23f151d/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index f28d496..e7f4733 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -76,6 +76,7 @@ public class Upgrade410to420 implements DbUpgrade {
         addHostDetailsIndex(conn);
         updateNetworksForPrivateGateways(conn);
         removeFirewallServiceFromSharedNetworkOfferingWithSGService(conn);
+        fix22xKVMSnapshots(conn);
     }
 
     private void updateSystemVmTemplates(Connection conn) {
@@ -779,4 +780,43 @@ public class Upgrade410to420 implements DbUpgrade {
         }
     }
 
+    private void fix22xKVMSnapshots(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        s_logger.debug("Updating KVM snapshots");
+        try {
+            pstmt = conn.prepareStatement("select id, backup_snap_id from 
`cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and 
backup_snap_id is not null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                String backUpPath = rs.getString(2);
+                // Update Backup Path. Remove anything before /snapshots/
+                // e.g 22x Path 
/mnt/0f14da63-7033-3ca5-bdbe-fa62f4e2f38a/snapshots/1/2/6/i-2-6-VM_ROOT-6_20121219072022
+                // Above path should change to 
/snapshots/1/2/6/i-2-6-VM_ROOT-6_20121219072022
+                int index = backUpPath.indexOf("snapshots"+File.separator);
+                if (index > 1){
+                    String correctedPath = File.separator + 
backUpPath.substring(index);
+                    s_logger.debug("Updating Snapshot with id: "+id+" original 
backup path: "+backUpPath+ " updated backup path: "+correctedPath);
+                    pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` 
set backup_snap_id=? where id = ?");
+                    pstmt.setString(1, correctedPath);
+                    pstmt.setLong(2, id);
+                    pstmt.executeUpdate();
+                }
+            }
+            s_logger.debug("Done updating KVM snapshots");
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to update backup id for 
KVM snapshots", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
 }

Reply via email to