Skip to main content
Code42 Support

Using Code42 API Examples On Github

Applies to:
  • CrashPlan PROe

Overview

Code42's API examples on GitHub provide useful, educational, and well-documented example scripts and code modules that can help you leverage the Code42 API. The vetted and approved code can give you a start on your own API-related project, and can give you real-life, working code examples to help you learn how to interact with and use the Code42 API.

Before using our GitHub examples, review our main API resources.

GitHub basics

In order to use our Github examples to their full potential, you should have some familiarity with Git, a command-line version control system, and GitHub, a web-based host of Git repositories. Both are explained in more detail below.

Git

Git is a distributed version control (or source control) system. It was developed to provide advantages over client-server based version control systems: it is fast, does not require constant network access, and is decentralized. Every user downloads a complete copy of the code. Users can create changes, new versions, and whole new branches, then merge changes back into the main branch (or a new branch) when the code is ready. Mistakes or changes can be easily undone.

Git is a command-line tool, although it includes some graphical user interface (GUI) tools, and third parties have created full GUI interfaces.

GitHub

GitHub provides a web interface to Git repositories, as well as apps that run on Windows, OS X, and mobile devices.. It allows users to collaborate, track changes, revert to a previous version of the code, or see who has created changes.

At Code42, we use GitHub to share our knowledge and examples to demonstrate the latest changes and up-to-date features of the Code42 API.

Learning more

The best way to learn about Git and GitHub is to start using them! You can easily sign up for a free account on GitHub, create your own project, and test the features.

We also recommend using these websites and resources to get started:

Retrieving scripts from GitHub

You can use the git command-line utility to retrieve scripts from GitHub. Run this command from a command line:

git clone https://github.com/code42/crashplan_api_examples.git

The git command copies the entire crashplan_api_examples script repository to your device:

Clone API example script repository to your filesystem

Code42 API scripts on GitHub

The current list of Code42 API scripts below is updated regularly. See the description for each script to find a script that contains the functionality you are looking for.

Archivereport.groovy

This Groovy script provides reports about restores from a user archive, including:

  • All restores performed by user in date range
  • All restores of user's archives in date range
  • All restores of user's specific archive in date range
  • All restores in date range

Resources

This script uses the following resources of the Code42 API:

  • User
  • Computer
  • RestoreRecord

Use case

You need to gather information about a user's restore for an audit or e-discovery process.

Edituserroles.py

This Python script adds or removes a role from all users in your Code42 environment or within a single organization. If an orgId is specified, then the script only removes or adds the role to users within the specified organization.

Resources

This script uses the following resources of the Code42 API:

  • User
  • UserRole

Use case

You need to modify the user roles of many users in your Code42 environment.

Example output

Before running the script, the users have these roles in the administration console:

EditUserRoles.py before

The script is run from a terminal window:

mac:api_scripts jjohnson$ python EditUserRoles.py 0 add test
Enter your CrashPlan console password: 
root        : INFO     User Role Action: add
root        : INFO     Users pulled from OrgId: All Orgs
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[1]:userName[admin]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[2]:userName[drakkarama@gmail.com]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[69]:userName[gjohnson]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[68]:userName[jgregory]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[66]:userName[jjohnson]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[4]:userName[mack]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[67]:userName[tjohnson]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[35]:userName[todd@code42.com]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[3]:userName[todd@toddojala.com]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[5]:userName[toddo]
requests.packages.urllib3.connectionpool: INFO     Starting new HTTP connection (1): 52.11.15.89
root        : INFO     Success: userRole[test] added for userId[34]:userName[tojala@gmail.com]
root        : INFO     Total Users affected: 11

After running the script, the users have these roles:

EditUserRoles.py after

Exportallusers.py

This Python script retrieves a list of all users in your Code42 environment.

Resources

This script uses the User resource of the Code42 API.

Use case

You need to audit a full list of all the users in your Code42 environment.

Example output

This example uses input output redirection to send the results to a CSV file:

mac:api_scripts jjohnson$ python ExportAllUsers.py > all_users.csv
Enter your CrashPlan console password: 
mac:api_scripts jjohnson$ ls
	ExportAllUsers.py	all_users.csv

This example creates a CSV file in the current working directory.

ExportAllUsers CSV

Deactivatedevices.py

This Python script deactivates user devices based on the number of months since they have last connected to your master server. You are able to specify the time period in months.

Resources

This script uses the following resources of the Code42 API:

  • Computer
  • ComputerDeactivation

Use case

You want to deactivate user devices that have not connected to your Code42 environment for a long period of time to free disk space and eliminate unnecessary use of licenses.

Potential data loss
This script deactivates devices, which can cause data loss. We recommend using the print option to test the effects before implementing deactivation.

Example output

In this example, the script lists devices that would be deactivated. Run this script using the print option before running with the deactivate option to avoid deactivating a user's device unintentionally.

mac:api_scripts johnson$ python deactivateDevices.py 1 nonverbose print
Building devices list... request count:  1
Building devices list... request count:  2
The following devices will be deactivated as they have not connected in more than 1 months:
device name: rt1 - XT1031
device name: Code's iPad
device name: WIN-PH8BSGDHNTJ
device name: WIN-PH8BSGDHNTJ
device name: Peter's iPad
device name: Peter's iPhone
device name: Peter's iPad
device name: Peter's iPhone
device name: Peter's iPhone
RUN_DEACTIVATION_SCRIPT set to false
TOTAL devices schdeuled to be deactivated: 10
TOTAL devices deactivated: 0
mac:api_scripts jjohnson$ 

Getarchivemetadata.sh

This Bash script walks you through the steps needed to navigate the file metadata in an archive. Edit the DEFAULT_* values near the top of this script. This script allows you to examine the metadata (name, path, last backup, size, and so on) of the files and directories stored for a particular device's archive.

This script is rather complex, and calls on many Code42 API resources. Before using this script in your Code42 environment, review this schematic diagram that explains its functionality.

Resources

This script uses the following resources of the Code42 API:

  • WebRestoreInfo
  • DataKeyToken
  • LoginToken
  • AuthToken
  • WebRestoreSession
  • WebRestoreTreeNode

Use case

You want to find out more about how the Code42 platform stores data in archives.

Example output

Review the PDF of sample output and usage.

Licenseavailabilityreport.py

This Python script returns the date that currently consumed user licenses will be available. This date is determined based on the archives' cold storage expiration date. A user license is released only after all of the user's archives are removed from cold storage.

Resources

This script uses the following resources of the Code42 API:

  • StorePoint
  • coldStorage
  • Computer
  • MasterLicense

Use case

You want to make currently consumed licenses available for use.

Example output

mac:api_scripts jjohnson$ python licenseAvailabilityreport.py nonverbose 0

Getting Store Points with Cold Storage

***********************************************************************
Getting Devices with Cold Storage

root        : INFO     Get a count of devices for the list of users with active devices.
root        : INFO     Building active device list... request count:  1
root        : INFO     Building active device list... request count:  2
root        : INFO     There are 5 users with at least one active device.

***********************************************************************
Getting the expiration date of the last expiring archive for each user.

***********************************************************************
Sorting and prepping for output.

root        : INFO     CrashPlanPROe License Availablity Summary 2015-03-30

root        : INFO     ========================================================
root        : INFO          1 license will be available   2016-02
root        : INFO     ========================================================
root        : INFO          1 total licenses to be made available.
root        : INFO          0 total licenses used with by users with active archives.
root        : INFO          1 total licenses currently being used.
root        : INFO     NOTE:  Licenses will become available when the cold storage archives expire or are removed.

Pushrestore.sh

This Bash script performs an automated push restore to a computer. You may specify:

  • One or more source files or directories
  • Remote restore directory

This script is able to restore files and directories stored in the public cloud or in your Code42 environment. It is able to do recursive restores (subdirectories). It can also restore to the computer of a user different than the owner of the source computer.

Resources

This script uses the following resources of the Code42 API:

  • RestoreRecord
  • Computer
  • Server
  • DataKeyToken
  • WebRestoreSession
  • PushRestoreJob

Use case

You would like to automate the restore process for a user or a group of users.

Example output

Please read our detailed article for example output and more information.

Totallicensecount.py

This Python script outputs a single number of currently used licenses.

Resources

This script uses the following resources of the Code42 API:

  • MasterLicense

Use case

You want to get a total count of the number of currently used licenses.

Example output

mac:api_scripts jjohnson$ python totalLicenseCount.py 1
Total Licensed Users:237

Searchchecksum.sh

This Bash script searches CrashPlan Archives for directories and files with a specific MD5 checksum, and outputs the results as a text file in CSV format. You can search a particular user's archives, all the archives in an organization, or all the archives in your entire Code42 environment. This script is most often used for e-discovery.

Resources

This script uses the following resources of the Code42 API:

  • Org
  • Computer
  • Archive
  • StorePoint
  • Server
  • ArchiveMetadata

Use case

You want to search the archives in your Code42 environment for a particular file's MD5 checksum.

Example output

mac:api_scripts jjohnson$ ./SearchChecksum.sh 
*************************************************************
——————————————————————————Code42—————————————————————————————
This is an unofficial script that is not supported.
Feel free to modify and use as you see fit.
*************************************************************

*************************************************************
———————————————————————SearchChecksum.sh—————————————————————————
This script searches CrashPlan Archives for directories and
files with a specific MD5 checksum.
Output is directed to the folder the script is run in.
It is designed for Private Deployments only.
*************************************************************


Enter Your Master Server IP
master.example.com
Enter Your Master Server Management Port
4285
Enter Your UserID
admin
Enter your Password
Enter the MD5 checksum to search for:
4cc67c6a9a5b15a6329b4df8a6b4b015
At which level would you like to search.  all, org, device?
all
Number of Devices scanned
9
Number of Devices matching search
1
Percentage positive search
11
Results can be found in the following file where the script is located.
SearchPath_Org_all_20150320144226.csv

Restorewatch.py

Resources

This python script uses the following resources of the Code42 API:

  • User
  • UserBlock
  • RestoreRecord

Use case

The script monitors and protects the CrashPlan archives of selected users in your Code42 environment against unauthorized or suspicious restore activity.

Example output

Please read our detailed article for example output and more information.

C42sharedlibscripts

This directory contains shared Python libraries that are used by other scripts.

External resources