← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4543: Added Advance MySQL Backup in INDIA Maintenance Module

 

------------------------------------------------------------
revno: 4543
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-09-08 11:13:00 +0530
message:
  Added Advance MySQL Backup in INDIA Maintenance Module
added:
  local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupFormAction.java
  local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupResultAction.java
  local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupForm.vm
  local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupResult.vm
modified:
  local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/TakeMySqlBackupAction.java
  local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-maintenance-in/src/main/resources/struts.xml
  local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupFormAction.java'
--- local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupFormAction.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupFormAction.java	2011-09-08 05:43:00 +0000
@@ -0,0 +1,82 @@
+package org.hisp.dhis.config.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+
+import com.opensymphony.xwork2.Action;
+
+public class AdvanceMySqlBackupFormAction implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+    // -------------------------------------------------------------------------
+    // Input and Output Parameters
+    // -------------------------------------------------------------------------
+    
+    private List<String> availableTables = new ArrayList<String>();
+    
+    public List<String> getAvailableTables()
+    {
+        return availableTables;
+    }
+    
+    private List<String> availableViews = new ArrayList<String>();
+    
+    public List<String> getAvailableViews()
+    {
+        return availableViews;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Action Implementation
+    // -------------------------------------------------------------------------
+
+    public String execute() throws Exception
+    {        
+       
+        //String query =  "SHOW TABLES";
+        String query =  "SHOW FULL TABLES";
+        
+        SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+        
+        while ( rs.next() )
+        {
+           // availableTables.add( rs.getString( 1 ) );
+            
+            String tableName =  rs.getString( 1 );
+            String tableType =  rs.getString( 2 );
+            
+            if( tableType.equalsIgnoreCase( "VIEW" ) )
+            {
+                availableViews.add( tableName );
+            }
+            else
+            {
+                availableTables.add( tableName );
+            }
+        }
+        
+        //System.out.println(" Total No of Tables is :" + availableTables.size() );
+        //System.out.println(" Total No of View is :" + availableViews.size() );
+        /*
+        int i =1;
+        for( String table : availableTables )
+        {
+            System.out.println(" Table " + i + " is : " + table );
+            i++;
+        }
+        */
+        return SUCCESS;
+    }
+}

=== added file 'local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupResultAction.java'
--- local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupResultAction.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/AdvanceMySqlBackupResultAction.java	2011-09-08 05:43:00 +0000
@@ -0,0 +1,178 @@
+package org.hisp.dhis.config.action;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.hisp.dhis.config.ConfigurationService;
+import org.hisp.dhis.config.Configuration_IN;
+import org.hisp.dhis.system.database.DatabaseInfoProvider;
+import org.springframework.beans.factory.annotation.Required;
+
+import com.opensymphony.xwork2.Action;
+
+public class AdvanceMySqlBackupResultAction implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    private ConfigurationService configurationService;
+
+    private DatabaseInfoProvider provider;
+ 
+    @Required
+    public void setConfigurationService( ConfigurationService configurationService )
+    {
+        this.configurationService = configurationService;
+    }
+
+    @Required
+    public void setProvider( DatabaseInfoProvider provider )
+    {
+        this.provider = provider;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Input and Output Parameters
+    // -------------------------------------------------------------------------
+    
+    private List<String> selectedTables = new ArrayList<String>();
+    
+    public List<String> getSelectedTables()
+    {
+        return selectedTables;
+    }
+
+    public void setSelectedTables( List<String> selectedTables )
+    {
+        this.selectedTables = selectedTables;
+    }
+
+    private String status;
+    
+    public String getStatus()
+    {
+        return status;
+    }
+    private String backupFilePath;
+
+    public String getBackupFilePath()
+    {
+        return backupFilePath;
+    }
+    
+    private String statusMessage;
+    
+    public String getStatusMessage()
+    {
+        return statusMessage;
+    }
+    
+    private SimpleDateFormat simpleDateFormat;
+    // -------------------------------------------------------------------------
+    // Action Implementation
+    // -------------------------------------------------------------------------
+
+    
+
+    public String execute() throws Exception
+    {        
+        status = "INPUT";
+        System.out.println(" Total No of Selected Tables for Backup is :" + selectedTables.size() );
+        
+        System.out.println( "Backup Start Time is : " + new Date() );
+        
+        String dbName = provider.getDatabaseInfo().getName();
+        String userName = provider.getDatabaseInfo().getUser();
+        String password = provider.getDatabaseInfo().getPassword();
+        
+        String mySqlPath = configurationService.getConfigurationByKey( Configuration_IN.KEY_MYSQLPATH ).getValue();
+        
+        Calendar curDateTime = Calendar.getInstance();
+        Date curDate = new Date();                
+        curDateTime.setTime( curDate );
+        
+        simpleDateFormat = new SimpleDateFormat( "ddMMMyyyy-HHmmssSSS" );
+                
+        String tempFolderName = simpleDateFormat.format( curDate );
+        
+        backupFilePath = configurationService.getConfigurationByKey( Configuration_IN.KEY_BACKUPDATAPATH ).getValue();
+        backupFilePath += tempFolderName;
+        
+        File newdir = new File( backupFilePath );
+        if( !newdir.exists() )
+        {
+            newdir.mkdirs();
+        }
+        
+        backupFilePath += "/" + "dhis2.sql";
+        //System.out.println(" MY-SQL Path is :" + mySqlPath );
+        String backupCommand = "";
+        
+        String temTables = "";
+        for( String table : selectedTables )
+        {
+            
+            temTables += " " + table;
+            //backupCommand += backupCommand + " " + table +" -r "+backupFilePath;
+        }
+        
+        //System.out.println(" Tables are :" + temTables );
+        
+        try
+        {
+            if( password == null || password.trim().equals( "" ) )
+            {
+                backupCommand = mySqlPath + "mysqldump -u "+ userName +" "+ dbName + " "+ temTables +" -r "+backupFilePath;
+                
+                //backupCommand = mySqlPath + "mysqldump -u "+ userName +" "+ dbName +" -r "+backupFilePath;
+            }
+            else
+            {
+                backupCommand = mySqlPath + "mysqldump -u "+ userName +" -p"+ password +" "+ dbName + " "+ temTables +" -r "+backupFilePath;
+                
+                //backupCommand = mySqlPath + "mysqldump -u "+ userName +" -p"+ password +" "+ dbName +" -r "+backupFilePath;
+            }
+            //System.out.println(" Backup Command is :" + backupCommand );
+            
+            Runtime rt = Runtime.getRuntime();
+            
+            Process process = rt.exec( backupCommand );
+            
+            process.waitFor();
+            
+            if( process.exitValue() == 0 )
+            {
+                statusMessage = "Backup taken succussfully at : "+backupFilePath;
+                
+                status = "SUCCESS";
+            }
+            else
+            {
+                statusMessage = "Not able to take Backup, Please try again";
+            }
+            
+        }
+        catch ( Exception e )
+        {
+            System.out.println("Exception : "+e.getMessage());
+            
+            statusMessage = "Not able to take Backup, Please check MySQL configuration and SQL file path.";
+        }
+        
+        //System.out.println(" Backup Path is :" + backupFilePath );
+        System.out.println( "Backup End Time is : " + new Date() );
+        /*
+        int i =1;
+        for( String table : selectedTables )
+        {
+            System.out.println(" Table " + i + " is : " + table );
+            i++;
+        }
+        */
+        return SUCCESS;
+    }
+}

=== modified file 'local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/TakeMySqlBackupAction.java'
--- local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/TakeMySqlBackupAction.java	2010-11-16 19:03:53 +0000
+++ local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/TakeMySqlBackupAction.java	2011-09-08 05:43:00 +0000
@@ -97,7 +97,7 @@
         }
         
         backupFilePath += "/" + "dhis2.sql";
-        
+        System.out.println(" MY-SQL Path is :" + mySqlPath );
         String backupCommand = "";
         
         try
@@ -111,6 +111,7 @@
                 backupCommand = mySqlPath + "mysqldump -u "+ userName +" -p"+ password +" "+ dbName +" -r "+backupFilePath;
             }
             
+            System.out.println(" Backup Command is :" + backupCommand );
             Runtime rt = Runtime.getRuntime();
             
             Process process = rt.exec( backupCommand );
@@ -134,8 +135,10 @@
             
             statusMessage = "Not able to take Backup, Please check MySQL configuration and SQL file path.";
         }
-
+        System.out.println(" Backup Path is :" + backupFilePath );
         return SUCCESS;
+        
+        
     }
-
+    
 }

=== modified file 'local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml	2010-11-16 19:03:53 +0000
+++ local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml	2011-09-08 05:43:00 +0000
@@ -38,5 +38,16 @@
     </property>
   </bean>
 
+<!-- Advance MySQL Backup -->
+  <bean id="org.hisp.dhis.config.action.AdvanceMySqlBackupFormAction" class="org.hisp.dhis.config.action.AdvanceMySqlBackupFormAction"
+    scope="prototype">
+	  <property name="jdbcTemplate" ref="jdbcTemplate"/>	
+  </bean>
 
+  <bean id="org.hisp.dhis.config.action.AdvanceMySqlBackupResultAction" class="org.hisp.dhis.config.action.AdvanceMySqlBackupResultAction"
+    scope="prototype">
+    <property name="configurationService" ref="org.hisp.dhis.config.ConfigurationService" />
+    <property name="provider" ref="databaseInfoProvider" />
+  </bean>	
+		
 </beans>

=== modified file 'local/in/dhis-web-maintenance-in/src/main/resources/struts.xml'
--- local/in/dhis-web-maintenance-in/src/main/resources/struts.xml	2010-10-28 09:17:13 +0000
+++ local/in/dhis-web-maintenance-in/src/main/resources/struts.xml	2011-09-08 05:43:00 +0000
@@ -44,7 +44,23 @@
             <param name="bufferSize">1024</param>
         </result>
     </action>
-
+<!-- Advance MySQL Backup -->
+	<action name="advanceMysqlBackupForm" class="org.hisp.dhis.config.action.AdvanceMySqlBackupFormAction">
+		<result name="success" type="velocity">/main.vm</result>
+        <param name="page">/dhis-web-maintenance-in/advanceMysqlBackupForm.vm</param>
+        <param name="menu">/dhis-web-maintenance-in/menu.vm</param>
+        <param name="stylesheets">css/StylesForTags.css</param>
+        <param name="requiredAuthorities">F_CONFIGURE_DOWNLOAD_BACKUP</param>
+    </action>
+	  
+	<action name="advanceMySQLBackupResult" class="org.hisp.dhis.config.action.AdvanceMySqlBackupResultAction">
+		<result name="success" type="velocity">/main.vm</result>
+        <param name="page">/dhis-web-maintenance-in/advanceMysqlBackupResult.vm</param>
+        <param name="menu">/dhis-web-maintenance-in/menu.vm</param>
+        <param name="stylesheets">css/StylesForTags.css</param>
+        <param name="requiredAuthorities">F_CONFIGURE_DOWNLOAD_BACKUP</param>
+    </action>	  
+	  
 <!-- Maintenance -->             
     <action name="maintenance" class="org.hisp.dhis.config.action.NoAction">
         <result name="success" type="velocity">/main.vm</result>

=== added file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupForm.vm'
--- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupForm.vm	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupForm.vm	2011-09-08 05:43:00 +0000
@@ -0,0 +1,115 @@
+<h3>Take Advance MySQL Backup</h3>
+<style>
+	#overlay 
+	{
+		z-index:19998;
+		position:absolute;
+		top:0;
+		bottom:0;
+		left:0;
+		width:100%;
+		background:#000;
+		opacity:0.45;
+		-moz-opacity:0.45;
+		filter:alpha(opacity=45);
+		visibility:hidden;
+	}
+
+	#overlayImg{ width: 50px; height: 50px; z-index: 9999; position: absolute; left:50%}
+</style>
+
+<script>
+	function formValidationsForAdvanceBackup()
+	{
+	
+		 var selectedTablesSize = document.advanceMySQLBackupForm.selectedTables.options.length;
+		 alert( " No of Selected Table(s) " + selectedTablesSize );	
+		 if(  selectedTablesSize <= 0 ) 
+		 {
+	        alert( "Please Select Table(s)" );
+	        return false;
+		 }
+		  
+		 if( selectedTablesSize > 0 )
+		 {
+			for( k=0;k<document.advanceMySQLBackupForm.selectedTables.options.length;k++ )
+    		{
+    			document.advanceMySQLBackupForm.selectedTables.options[k].selected = true;
+        	} 
+		 }
+		  showOverlay()
+  		  return true;
+	} 
+
+</script>
+
+<script>
+    
+	function showOverlay() 
+	{
+		var o = document.getElementById('overlay');
+		o.style.visibility = 'visible';
+		jQuery("#overlay").css({
+			"position":"fixed",
+            "top":0+"px",
+            "left":0+"px",
+			"height": jQuery(document).height(),
+			"width": jQuery(document).width()
+		});
+		jQuery("#overlayImg").css({
+			"top":jQuery(window).height()/2
+		});
+	}
+	
+	function hideOverlay() 
+	{
+		var o = document.getElementById('overlay');
+		o.style.visibility = 'hidden';
+	}
+
+</script>
+
+	
+<form id="advanceMySQLBackupForm" name="advanceMySQLBackupForm" action="advanceMySQLBackupResult.action" method="POST" onsubmit="return formValidationsForAdvanceBackup()">
+	<table>
+		<tr>
+			<td valign="top">
+				<table valign="top">
+
+					<tr><td>&nbsp;</td></tr>
+					
+					<tr><th>Available Tables</th><td></td><th>Selected Tables</th></tr>
+					
+					<tr>	
+						<td>	
+							<select id="availableTables" name="availableTables" multiple="multiple" style="min-width:325px;height:11.25em" ondblclick="moveSelectedById( this.id, 'selectedTables' )">
+								#foreach( $table in $availableTables )
+    								<option value="$table" title="$table">$table</option>
+	    						#end
+							</select>
+						</td>
+						<td style="text-align:center">			
+							<input type="button" value="&gt;" title="$i18n.getString('move_selected')" style="width:50px" onclick="moveSelectedById( 'availableTables', 'selectedTables' )" /><br/>
+							<input type="button" value="&lt;" title="$i18n.getString('remove_selected')" style="width:50px" onclick="moveSelectedById( 'selectedTables', 'availableTables' )" /><br/>
+							<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="moveAllById( 'availableTables', 'selectedTables' )"/><br/>
+							<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="moveAllById( 'selectedTables', 'availableTables' )"/>			
+						</td>	
+						<td>
+							<select id="selectedTables" name="selectedTables" size="2" multiple="multiple" style="min-width:325px;height:11.25em" ondblclick="moveSelectedById( this.id, 'availableTables' )"></select>
+						</td>
+					</tr>
+					<tr><td><h4><strong>No of Available Tables :&nbsp;$availableTables.size()</strong></h4></td></tr>
+					<tr>
+						<td>
+							<input type="submit" id="takeBackup" name="takeBackup" value="Take Backup" style="width:10em"  />
+				   		</td>
+			  		 </tr>
+				</table>
+			</td>
+		</tr>
+	</table>
+</form>
+<div id="overlay">
+	<div id="overlayImg"><img  width="50" height="50" src="images/ajax-loader.gif" /></div>
+</div>
+

=== added file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupResult.vm'
--- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupResult.vm	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/advanceMysqlBackupResult.vm	2011-09-08 05:43:00 +0000
@@ -0,0 +1,15 @@
+
+
+<br /><br />
+
+<h3>$statusMessage
+	#if( $!status == "SUCCESS" ) 
+		<a href="streamMySQLBackup.action?backupFilePath=$backupFilePath"><img  width="60" height="50" src="images/download-icon.jpg" /></a>
+	#else
+		<h4><strong>No of Selected Tables :&nbsp;$selectedTables.size()</strong></h4>	
+	#end
+</h3>
+
+<p>
+	<input type="button" value="BACK" onclick="window.location.href='advanceMysqlBackupForm.action'" style="width:100px" />
+</p>
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm'
--- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm	2010-10-28 09:17:13 +0000
+++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm	2011-09-08 05:43:00 +0000
@@ -29,6 +29,7 @@
         <li><a href="configForm.action">Configuration</a></li>
         <li><a href="takeMysqlBackupResult.action" onclick="showOverlay()">Take MySQL Backup</a></li>
 		<li><a href="maintenance.action">Maintenance</a></li>
+		<li><a href="advanceMysqlBackupForm.action">Advance MySQL Backup</a></li>
     </ul>
 </ul>