npm.io
2.0.4 • Published 5 years ago

@mindset-swiss/backup-to-sharepoint

Licence
ISC
Version
2.0.4
Deps
5
Size
11 kB
Vulns
24
Weekly
0

@mindset-swiss/backup-to-sharepoint

To backup a folder or file to sharepoint folder using node js

Install

$ npm install @mindset-swiss/backup-to-sharepoint

Getting Started

  1. Create a new app in the target directory (Azure Portal > Azure Active Directory > App Registration > New Application Registration).
  2. In the Create screen, enter the following information: Name: Can be any name, for example, "MicrosoftGraphClient." Type: Must be "Web App/API" for our needs. Sign-On URL: Not important (since we do not intend users to directly login to the app), for our case, we should put it under the tenant directory. For example,https://.onmicrosoft.com/MicrosoftGraphClient
  3. Get the Client ID: Note the Application ID - It is the Client ID, so we need the following steps.
  4. Create a new Client Secret: Navigate to App > Keys > Passwordsand add a new key.
    • Name (description): enter a descriptive name for the key so you later know that the client application is using it (you can have more than one key per app).
    • Expires: Choose "Never Expire," unless you want to change your key every year or two.
    • Click Save - a new Client Secret will be generated for you. This will be the only time you will see the Client Secret, so you better copy it to a secured location otherwise you won't be able to retrieve it again!
  5. Grant permissions within the Azure console (application directory > API Permissions)
    • requires Microsoft Graph Files.ReadWrite.All
    • type Application
    • Then it will require the admin approval

By default each running of the app will create a new folder labeled as the current date, if the current date folder already exists it will update the same folders and create a new version of each file on sharepoint

Usage

const oneDriveBackup = require("@mindset-swiss/backup-to-sharepoint");

// To run a single backup
var failures = await oneDriveBackup.startBackup({
    backupFolderPath: '/home/ubuntu/Documents/.../FolderToBackup', // The path to the folders you wish to backup and deploy
    oneDriveFolderName: 'Project Backup',
    directoryID: "XXXXX", // Your unique directoryID (The directory name can be found by hovering over our name in the Azure Portal)
    driveID: "XXXXX", // Your unique driveID/name
    client_id: "XXXXX", // Miscrosoft App client ID
    client_secret: "XXXXX", // Miscrosoft App client Secret
});
// Depending on the size of your folders/files, this can take some time
//=> []  Will return an array with all the files which failed to uploaded

// To run a daily backup but only keep a 7 day history (delete based on folder name date) -- need to use a cron job to run it everday
oneDriveBackup.dailyBackup7Days(
    {
        backupFolderPath: '/home/ubuntu/Documents/.../FolderToBackup', // The path to the folders you wish to backup and deploy
        oneDriveFolderName: 'Project Backup',
        directoryID: "XXXXX", // Your unique directoryID (The directory name can be found by hovering over our name in the Azure Portal)
        driveID: "XXXXX", // Your unique driveID/name
        client_id: "XXXXX", // Miscrosoft App client ID
        client_secret: "XXXXX", // Miscrosoft App client Secret
    }
);

console.log(failures)