DB2 database automatic backup method

xiaoxiao2021-04-03  216

Proceed as follows:

(1) Write Bak.java, the code is as follows: (Saturday is complete in a week, other date incremental backup)

Import java.util.date;

Public class bak {

Public static void main (string [] args) throws exception {

Runtime runtime = runtime.getRuntime ();

// Disconnect the database connection

Process proc = runtime.exec ("DB2CMD / C DB2 Force Application All");

// only keep one day backup

//runtime.exec( "Del D: //backup//db2bak//autobak//datacTr.0// / s / f / q ");

//runtime.exec( "Del D: //backup//db2bak//autobak//rone.0// / s / f / q ");

/ / -------------------------------------------------------------------------------------------- ---------------

// Pause n second

Thread.currentthread (). SLEEP (5000);

// Close the above process

//proc.destroy ();

// --------------------------------------

// Pause n second, wait for the database connection to disconnect

//Thread.currentthread ().sleep (5000);

// Backup

// proc = runtime.exec ("DB2CMD DB2 Backup DB Datactr");

//Thread.currentthread ().sleep (5000);

//proc.destroy ();

// --------------------------------------

Date Date = new date ();

INT dayoftheweek = Date.getDay ();

IF (dayoftheweek! = 6) {

/ / Not on Saturday, incremental backup

// proc = runtime.exec ("DB2CMD DB2 Backup DB Yndc Incremental");

Proc = runtime.exec ("DB2CMD / C DB2 Backup DB Yndc Incremental");

}

Else {

/ / Is Saturday, fully backed up

Proc = runtime.exec ("DB2CMD / C DB2 Backup DB Yndc");

}

// proc = runtime.exec ("DB2CMD DB2 Backup DB Gather");

Proc = runtime.exec ("DB2CMD / C DB2 Backup DB CodeBase");

Proc = runtime.exec ("DB2CMD / C DB2 Backup DB RONE");

// proc = runtime.exec ("DB2CMD DB2 Backup DB Datactr");

// Pause 5 seconds

//Thread.currentthread ().sleep (5000);

//proc.destroy ();

// --------------------------------------

// Restart DB2

// Proc = runtime.exec ("db2start");

// Pause 5 seconds

//Thread.currentthread (). SLEEP (5000); // proc.destroy ();

// --------------------------------------

Runtime.exit (0);

}

}

(2) Write Run.Bat, compile BAK.JAVA and execute (note that the Windows environment variable points to JDK's bin directory, "Java" can be found in the CMD to find this command to support compilation and execute Bak.java

Javac -DepRecation Bak.java

Java Bak

(3) Task by Windows plans to call Run.bat every night to make database backup, such as 22:00 per night.

(4) Cooperating with WinZip software to implement a database of databases, the backup directory is compressed to another machine's hard drive (which can map the network hard disk of the local machine.)

Note: The DB2 Backup command does not support backing up the backup file directly on the network hard disk, and the prompt cannot be identified

Offline backup or online backup can be selected as required.

转载请注明原文地址:https://www.9cbs.com/read-131676.html

New Post(0)