Schedule SharePoint Replication on Mac OS X
You can use CData Sync for SharePoint to replicate SharePoint data from your Mac. Synchronize SharePoint data with any of the major cloud-based and on-premises databases. In this article we will use the cross-platform edition of Sync and Mac OS X tools to schedule replication to SQLite. We show how to use the Automator application to create a calendar event, as well as how to integrate Sync with your launchd jobs.
About SharePoint Data Integration
Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:
- Access data from a wide range of SharePoint versions, including Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007 and above, and SharePoint Online.
- Access all of SharePoint thanks to support for Hidden and Lookup columns.
- Recursively scan folders to create a relational model of all SharePoint data.
- Use SQL stored procedures to upload and download documents and attachments.
Most customers rely on CData solutions to integrate SharePoint data into their database or data warehouse, while others integrate their SharePoint data with preferred data tools, like Power BI, Tableau, or Excel.
For more information on how customers are solving problems with CData's SharePoint solutions, refer to our blog: Drivers in Focus: Collaboration Tools.
Getting Started
Obtain Prerequisites
If you have not already done so, download a free trial for Sync. The installer is packaged as a ZIP archive. After extracting the installer, setup.jar, open Terminal and navigate to the setup folder:
cd ~/Downloads/setup
You can then start the installation with the following commands:
java -jar setup.jar
The setup.jar installs Sync to the CData subfolder in the Applications folder. The JAR file for Sync is located in the lib subfolder of the installation folder.
If you are not using one of the included drivers, you will also need to download the driver for your replication database.
Connect to SharePoint and Your Replication Database
Specify the connection properties to SharePoint and your replication database in the XML configuration file.
Below is an example configuration to replicate SharePoint data to an SQLite database:<CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>org.sqlite.JDBC</DatabaseProvider> <ConnectionString>User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;</ConnectionString> <ReplicateAll>False</ReplicateAll> <DatabaseConnectionString>Data Source=my.db</DatabaseConnectionString> </CDataSync>
Set the URL property to the base SharePoint site or to a sub-site. This allows you to query any lists and other SharePoint entities defined for the site or sub-site.
The User and Password properties, under the Authentication section, must be set to valid SharePoint user credentials when using SharePoint On-Premise.
If you are connecting to SharePoint Online, set the SharePointEdition to SHAREPOINTONLINE along with the User and Password connection string properties. For more details on connecting to SharePoint Online, see the "Getting Started" chapter of the help documentation
Replicate SharePoint Tables
Specify the tables you want to replicate in the SQL file. If you want to replicate an entire table, you can use the syntax REPLICATE [tablename]. This example uses the following query:
REPLICATE MyCustomList;
The REPLICATE statement gives you high-level control over replication. By default, Sync will update tables and schemas incrementally. A variety of other options give you complete control over the replication through standard SQL. Sync supports any of the capabilities of the SharePoint API through standard SQL.
Write a Script to Start Sync
In the following sections you will use a quick script that configures the application through the command-line interface. Save the following code into runupdate.sh in your home folder:
#!/bin/sh cd /Applications/CData/CData\ Sync\ for\ SharePoint\lib java -Xbootclasspath/p:sqlitejdbc.jar -jar SharePointSync.jar \ -f MySQLFile.sql \ -g MyConfigFile.xml \
Note: Use the -Xbootclasspath flag to add the driver for your replication database to the classpath.
Create a Calendar Alarm to Schedule Sync
The Automator application provides a graphical way to schedule tasks on Mac OS X. You will configure Automator to start the application. The application can be started through the command-line interface (CLI).
To start using Automator, launch Automator from the Applications folder. In the dialog that is displayed, click Calendar Alarm and drag the Run Shell Script action onto the main workflow. To execute the script, enter the following command:
sh ~/runupdate.sh
After you save the Automator calendar event, Calendar is opened and the calendar alarm you created is added to an event. Double-click the event to change the calendar event as desired.
Use launchd to Schedule Sync
As an alternative to Automator, you can load update jobs into the launchd process manager. Define jobs in XML-based plist files. A variety of keys can be configured in the file and enable a greater degree of customization than Automator. You can use the LaunchControl graphical user interface (GUI) or the launchctl command-line tool. Follow the steps below to create a user agent to run Sync as the currently logged-in user:
LaunchControl
- In LaunchControl, click File -> New.
- In the Program to run pane, enter the path to the script that you created in the previous section.
- Drag and drop filter keys onto the job. Use the StartCalendarInterval key to specify the date and time you want to run the job. You can select the desired intervals from the menu or enter a cron-style time specification.
launchctl
You can write your own job definitions and load them with the launchctl tool. Below is a sample job definition. The definition uses the StartInterval key to update the database every 5 minutes (300 seconds). The RunAtLoad key specifies that the job starts as soon as the job definition is loaded:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>sync.job</string> <key>Program</key> <string>/Users/MyUser/runupdate.sh</string> <key>RunAtLoad</key> <true/> <key>StartInterval</key> <integer>300</integer> </dict> </plist>
You can load your job definition with the command below:
launchctl load PathToYourPlist