Giter VIP home page Giter VIP logo

gradle-backup-plugin's Introduction

gradle-backup-plugin

Build Status Dependency Status Download latest version

This Gradle plugin allows you to automate small non-production backups and upload them into various clouds.

Currently it can upload things to:

You can create ZIP and TAR archives using awesome Gradle's out-of-the-box features! And if you're really paranoid you can encrypt them with your favourite Java encryption library before the uploading.

Usage

The plugin is available via jCenter repository. To use it, add the following lines into your build.gradle:

buildscript {
	repositories {
		jcenter()
	}

	dependencies {
		classpath 'by.dev.madhead:gradle-backup-plugin:latest.release'
	}
}

Latest snapshots are avaiable at OJO. To use them, add the following:

buildscript {
	repositories {
		maven {
			url 'http://oss.jfrog.org/oss-snapshot-local'
		}
	}

	dependencies {
		classpath 'by.dev.madhead:gradle-backup-plugin:1.0.5-SNAPSHOT'
	}
}

After that your buildscript will be enhanced with the task types from the plugin.

Creating archive

First, you need to create a backup archive. It can be ZIP or TAR (they are very simple to create with Gradle), or custom archive (in this case you might need to write a few lines of your own code). For example, creating TAR archive:

task createTarball(type: Tar) {
	baseName = 'calibre-' + new Date().format('yyyy-MM-dd_hh-mm')
	destinationDir = project.buildDir
	compression = Compression.GZIP
	from project.projectDir
	excludes = [
		'build/**',
		'build.gradle'
	]
}

After the archive is ready you want to upload it into a cloud.

Uploading to the Google Drive

You'll need to create your own project in Google Developers Console. Don't worry, it's very easy and free.

Create a project with any name and ID you like. After that, open it and go to APIs & auth โ†’ APIs. Search for Drive API and enable it. Then, navigate to APIs & auth โ†’ Credentials and create new OAuth 2.0 app (Create new Client ID). Choose Installed application with type Other. You might be asked to fill Consent screen before being able to create the app. That's ok, data on that screen will be seen only by you.

After the app is created, store it's Client ID and Client Secret in environment variables on your system for future access with System.getenv(). You might choose another way to store them and pass to the tasks.

Before talking to Google Drive API, you need to grant access token to the app you've created. The plugin contains a class named ObtainGoogleDriveTokensTask which will help you:

task obtainGoogleDriveTokens(type: by.dev.madhead.gbp.tasks.gdrive.ObtainGoogleDriveTokensTask) {
	clientId = System.getenv('CALIBRE_BACKUP_GDRIVE_CLIENT_ID')
	clientSecret = System.getenv('CALIBRE_BACKUP_GDRIVE_CLIENT_SECRET')
}

Run gradle obtainGoogleDriveTokens, follow the instructions and you'll get Access Token and Refresh Token which are used to communicate the Google Drive API. Store them in environment variables too.

Now all you need to do is to configure upload task:

task backup(type: by.dev.madhead.gbp.tasks.gdrive.GoogleDriveUploadTask) {
	clientId = System.getenv('CALIBRE_BACKUP_GDRIVE_CLIENT_ID')
	clientSecret = System.getenv('CALIBRE_BACKUP_GDRIVE_CLIENT_SECRET')
	accessToken = System.getenv('CALIBRE_BACKUP_GDRIVE_ACCESS_TOKEN')
	refreshToken = System.getenv('CALIBRE_BACKUP_GDRIVE_REFRESH_TOKEN')

	dependsOn createTarball                 // 1
	mimeType = 'application/x-gtar'         // 2
	archive = createTarball.archivePath     // 3
	path = ['Backups', 'Calibre']           // 4
	listenForUpload = true                  // 5
}
  1. Tolds Gradle to execute createTarball before uploading the results.
  2. Helps Google Drive to recognize what is being uploaded. You'll be able to work with archive in the cloud without downloading if you have apps for that MIME type installed.
  3. Specifies the file to upload.
  4. Specifies destination path inside Google Drive starting from the root to put the archive.
  5. Enables drawing text-based progress bar tracking the upload process.

That's all. Run gradle backup and you'll get your backup in a cloud:

image

gradle-backup-plugin's People

Contributors

madhead avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.