Code42 API examples on GitHub
Who is this article for?
Incydr, no.
CrashPlan for Enterprise, yes.
Code42 for Enterprise, yes.
CrashPlan for Small Business, no.
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, Mac, 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.
Learn 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:
- Getting started with Git:
- Download a Git client for your platform.
- Read Git's online book: Pro Git.
- Getting started with GitHub:
- Read the Github help site.
- Watch LearnCode.academy's GitHub Tutorial for Beginners video.
If you need assistance with Code42 scripts on GitHub, contact your Customer Success Manager (CSM) to engage the Code42 Professional Services team.
Retrieve scripts from GitHub
Code42 API example scripts are available from:
https://github.com/code42/crashplan_api_examples
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.
Examples of Code42 API scripts available on GitHub
Following are just some of the Code42 API scripts available on GitHub. For a complete list, see the readme file:
https://github.com/code42/crashplan_api_examples/blob/master/README.md
Review the readme file to find a script that contains the functionality you are looking for.
Deactivatedevices.py
This Python script deactivates user devices based on the number of months since they have last connected to your authority 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.
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$
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 Code42 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.
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 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.
Searchchecksum.sh
This Bash script searches 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 Server IP master.example.com Enter Your 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