Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
Expand All @@ -28,5 +30,27 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
target
./dependency-reduced-pom.xml
/backup
.DS_Store
.idea/
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Smartsheet Account Backup Utility

License and Warranty
--------------------
Copyright 2013 Smartsheet.com
Copyright 2013-2020 Smartsheet.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,14 @@ This command-line backup utility takes a snapshot of the data in a Smartsheet Te

Release History
------------
* Jan 21, 2020 - fixed a broken link in the Readme
* Nov 9, 2018 - version 1.6.2:
- Updated vulnerable dependencies.
* Apr 28 2016 - version 1.6.1:
- Changed extension of generated files from .xls to .xlsx
Updated to support Smartsheet API version 2.0
* Mar 2 2016 - version 1.6.0:
- Updated to support Smartsheet API version 2.0
* Feb 11 2015 - version 1.5.2:
- Added the api error code and error response to the log if a request fails.
* Apr 23 2014 - version 1.5.1:
Expand All @@ -50,7 +58,7 @@ Release History
Requirements
------------
* Java Runtime Edition 7 (latest version)
* API access token generated by a Smartsheet account administrator (SysAdmin). Please see this help article [http://help.smartsheet.com/customer/portal/articles/520100-user-types](http://help.smartsheet.com/customer/portal/articles/520100-user-types) to learn about Smartsheet user types, and [http://www.smartsheet.com/developers/api-faq](http://www.smartsheet.com/developers/api-faq) for instructions on how to generate an API access token.
* API access token generated by a Smartsheet account administrator (SysAdmin). Please see this help article [http://help.smartsheet.com/customer/portal/articles/520100-user-types](http://help.smartsheet.com/customer/portal/articles/520100-user-types) to learn about Smartsheet user types, and the [Authentication and Access Tokens](https://smartsheet-platform.github.io/api-docs/#authentication-and-access-tokens) topic in the API Documentation for instructions on how to generate an API access token.


Limitations
Expand All @@ -72,9 +80,9 @@ How it works

Usage
------------
First, download the backup zipped archive from the Developer Portal tools page [here](https://googledrive.com/host/0B7xwgf7q3I5ITzFkLUFpa2hUUTQ/smartsheet-org-backup-1.5.2.zip). Unzip the archive - it will contain the JAR executable and a sample properties file.
First, download the backup zipped archive [here](https://github.com/smartsheet-platform/backup-java/releases/download/1.6.2/smartsheet-org-backup-1.6.2.zip). Unzip the archive - it will contain the JAR executable and a sample properties file.

The tool will look for smartsheet-backup.properties file in the current directory (the directory from which it is being executed).
The tool will look for `smartsheet-backup.properties` file in the current directory (the directory from which it is being executed).
Edit the properties file to set the following parameters:

* **accessToken** (required) - access token that belongs to your Smartsheet account administrator. See the Requirements section above on how to get an access token
Expand All @@ -84,7 +92,7 @@ Edit the properties file to set the following parameters:
* **downloadThreads** (optional, default is 4) - set to desired number of threads used to download attachments
* **allDownloadsDoneTimeout*** (optional, default is 2<sup>^32</sup>-1) - The total number of minutes to wait for the attachment downloads to finish.

To execute the backup, run the following command "java -jar smartsheet-org-backup.jar". Please replace with the current version of the backup tool - for instance, "1.5.1". You can determine the version easily by simply listing the contents of the directory and looking for the .jar file.
To execute the backup, run the following command `java -jar smartsheet-org-backup.jar`. Please replace with the current version of the backup tool - for instance, "1.5.1". You can determine the version easily by simply listing the contents of the directory and looking for the .jar file.
Since it's a runnable jar, you don't need to set classpath or copy other jars. Everything you need is in the runnable jar.


Expand Down
9 changes: 8 additions & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.smartsheet.tools</groupId>
<artifactId>smartsheet-org-backup</artifactId>
<name>Smartsheet Org Backup</name>
<version>1.5.2</version>
<version>1.6.1</version>
<description>Backs up the Smartsheet sheets of all users in an organization to a local directory.</description>
<build>
<pluginManagement>
Expand Down Expand Up @@ -38,6 +38,13 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.smartsheet.tools</groupId>
<artifactId>smartsheet-org-backup</artifactId>
<version>1.5.2</version>
<version>1.6.2</version>
<name>Smartsheet Org Backup</name>
<description>Backs up the Smartsheet sheets of all users in an organization to a local directory.</description>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.4</version>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
Expand Down Expand Up @@ -53,6 +53,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down
3 changes: 2 additions & 1 deletion smartsheet-backup.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
accessToken=[access token]
accessToken=
outputDir=backup/smartsheet-backup
#continueOnError=true
#zipOutputDir=true
#downloadThreads=4
#allDownloadsDoneTimeout=2
#smartsheetApiBaseUrl=https://api.smartsheetgov.com/2.0/
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ public Object clone() throws CloneNotSupportedException {
ecss.delegateService = (SmartsheetService) this.delegateService.clone();
return ecss;
}

@Override
public String getApiBaseUrl() {
return delegateService.getApiBaseUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@
*/
public class RestfulSmartsheetService implements SmartsheetService, Cloneable {

public static final String API_BASE_URL = "https://api.smartsheet.com/2.0/";
public static final String DEFAULT_API_BASE_URL = "https://api.smartsheet.com/2.0/";
public final String API_BASE_URL;

private String accessToken;
private String assumedUserEmail;

public RestfulSmartsheetService(String accessToken) {
this.accessToken = accessToken;
this.API_BASE_URL = this.DEFAULT_API_BASE_URL;
}

public RestfulSmartsheetService(String accessToken, String apiBaseUrl) {
this.accessToken = accessToken;
this.API_BASE_URL = apiBaseUrl;
}

@Override
Expand Down Expand Up @@ -104,4 +111,9 @@ public Object clone() throws CloneNotSupportedException {

return rss;
}

@Override
public String getApiBaseUrl() {
return this.API_BASE_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,8 @@ public Object clone() throws CloneNotSupportedException {
return rss;
}

@Override
public String getApiBaseUrl() {
return delegateService.getApiBaseUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface SmartsheetService {
void assumeUser(String assumedUserEmail);

String getAssumedUser();

String getApiBaseUrl();

public Object clone() throws CloneNotSupportedException;
}
8 changes: 4 additions & 4 deletions src/main/java/com/smartsheet/tools/SheetSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class SheetSaver {

private static final String XLS_EXTENSION = ".xls";
private static final String XLSX_EXTENSION = ".xlsx";

private final SmartsheetService apiService;
private final ParallelDownloadService parallelDownloadService;
Expand All @@ -62,8 +62,8 @@ public SheetSaver(SmartsheetService apiService, ParallelDownloadService parallel
* @throws Exception
*/
public File save(SmartsheetSheet sheet, File folder) throws Exception {
File sheetFile = createFileFor(sheet, folder.getAbsolutePath(), XLS_EXTENSION);
String url = RestfulSmartsheetService.API_BASE_URL + "sheets/" + sheet.getId();
File sheetFile = createFileFor(sheet, folder.getAbsolutePath(), XLSX_EXTENSION);
String url = apiService.getApiBaseUrl() + "sheets/" + sheet.getId();
String accessToken = apiService.getAccessToken();
String userToAssume = apiService.getAssumedUser();
try {
Expand Down Expand Up @@ -152,7 +152,7 @@ public File saveSummary(SmartsheetAttachment attachment, SmartsheetSheet sheet,
* already exists in the folder. In that case a number will be appended to
* the file name starting from 2 (such as "sheet name (2)") and upward until
* a unique file name is found in the folder. An optional file extension can
* also be specified (for example when you want to use ".xls" as the
* also be specified (for example when you want to use ".xlsx" as the
* extension of the file which a sheet is saved to.
*/
public static File createFileFor(SmartsheetNamedEntity item, String folder, String extension) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public int backupOrgTo(File backupFolder) throws Exception {
// for each active user, assume the identity of the user to
// backup that user's sheets in the user's context (e.g., what
// sheets they own, the hierarchy they see in Smartsheet, etc.)
if (status.equals(USER_ACTIVE_STATUS)) {
if (status != null && status.equals(USER_ACTIVE_STATUS)) {

ProgressWatcher.getInstance()
.notify(String.format(
Expand All @@ -129,6 +129,7 @@ public int backupOrgTo(File backupFolder) throws Exception {
} else {
// user not active yet and will result in 401 (Unauthorized)
// if try to assume their identity, so skip...
status = (status != null) ? status : "status unknown";
ProgressWatcher.getInstance()
.notify(String.format(
"--------------------SKIP backup for user [%d of %d]: %s (%s)--------------------",
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/smartsheet/tools/SmartsheetBackupTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ public static void main(String[] args) {
int downloadThreads = getOptionalProp(props, "downloadThreads",
DEFAULT_DOWNLOAD_THREADS, 1);

String apiBaseUrl = getOptionalProp(props, "smartsheetApiBaseUrl");

// 2. instantiate services
RestfulSmartsheetService restfulService = apiBaseUrl == null ?
new RestfulSmartsheetService(accessToken) :
new RestfulSmartsheetService(accessToken, apiBaseUrl);
SmartsheetService apiService = new ErrorContextualizingSmartsheetService(
// the ErrorContextualizingSmartsheetService wraps the
// RetryingSmartsheetService:
new RetryingSmartsheetService(
// the RetryingSmartsheetService wraps the
// RestfulSmartsheetService:
new RestfulSmartsheetService(accessToken)));
restfulService));

ParallelDownloadService parallelDownloadService = new ParallelDownloadService(downloadThreads);

Expand Down Expand Up @@ -247,4 +252,12 @@ private static boolean getOptionalProp(Properties props, String propName,

return Boolean.valueOf(prop);
}

private static String getOptionalProp(Properties props, String propName) {
String prop = props.getProperty(propName);
if (prop == null || prop.trim().isEmpty())
return null;

return prop;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.smartsheet.tools.SmartsheetBackupTool

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public String getAssumedUser() {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}

@Override
public String getApiBaseUrl() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public String getAssumedUser() {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}

@Override
public String getApiBaseUrl() {
return null;
}
}