Team Elements

Status: Caution PostgreSQL Open Source Initiative (OSI) Java
PUBLIC PROFILE

Backup and Restore

Backup and Restore Requirements

This script requires:

  • bsh.jar (for running the example from the command-line; code could be compiled as an app or into another application)
  • team_elements_tools.jar (for the TE API)
  • sjssxp.jar (for streaming the resulting xml data directly into a file)
  • jsr-173.jar

The 3rd-party jars can be found here:
https://svn.teamelements.com/iteam/trunk/lib

A copy of the scripts are here:
https://svn.teamelements.com/iteam/trunk/bin/backupProjects.bsh
https://svn.teamelements.com/iteam/trunk/bin/restoreProjects.bsh

Backup Projects

The backup API can be triggered by a command-line script which in turn uses the API...

#!/bin/sh
//bin/true; exec java -classpath .:lib/bsh-2.0b4.jar:dist/team_elements_tools-0.9.3.jar:lib/sjsxp-1.0.jar:lib/jsr173_1.0_api.jar bsh.Interpreter "$0" "$@"

import com.zeroio.utils.APIConnection;
import org.aspcfs.apps.transfer.DataRecord;

print("Starting backup...");

APIConnection conn = new APIConnection();
conn.setUrl("http://127.0.0.1:8080");
conn.setClientId(1);
conn.setCode("plaintext-code-in-database");

// To stream the HTTP result to a file and conserve memory set a filename...
File file = new File("backup.xml");
conn.setOutputFile(file);

// Save the projectList and all project-dependent data
// Users are not backed up in this example
DataRecord record = new DataRecord();
record.setName("projectList");
// A specific project, or comment out for all projects
//record.addField("projectId", 41);
record.setAction(DataRecord.BACKUP);
conn.save(record);

Restoring Projects

Using an XML backup file, the API is used to restore 1 or all projects in that file. The client will seek, if specified, to the project to be restored.

Project data overwrites the existing project data, or optionally creates a copy.

#!/bin/sh
//bin/true; exec java -classpath .:lib/bsh-2.0b4.jar:dist/team_elements_tools-0.9.3.jar:lib/sjsxp-1.0.jar:lib/jsr173_1.0_api.jar bsh.Interpreter "$0" "$@"

import com.zeroio.utils.APIConnection;
import com.zeroio.utils.APIRestore;
import org.aspcfs.apps.transfer.DataRecord;
import org.aspcfs.apps.transfer.DataField;
import org.aspcfs.apps.transfer.DataRecordFactory;
import org.aspcfs.apps.transfer.PropertyList;

import java.io.File;
import java.util.ArrayList;

File file = new File("backup.xml");

APIConnection conn = new APIConnection();
conn.setUrl("http://127.0.0.1:8080");
conn.setClientId(1);
conn.setCode("plaintext-code-in-database");

ArrayList meta = new ArrayList();
// Create a copy during restore
//meta.add("mode=copy");
// Restore the state of the objects as-supplied, start by deleting the record and dependents
meta.add("mode=overwrite");
conn.setTransactionMeta(meta);

// A deep restore is done... a project and its dependent data
// MUST turn off autocommit
conn.setAutoCommit(false);
APIRestore.restore(conn, file, "project", 41);
//APIRestore.restoreAll(conn, file);
conn.commit();

System.out.println("Returned: " + (conn.hasError() ? "error" : "success" ));

Sign in to add your comment.