Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
savageautomate committed Mar 4, 2022
0 parents commit 770b197
Show file tree
Hide file tree
Showing 12 changed files with 2,152 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
backup
Dockerfile
.gitignore
.git
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Backup directory
backup

# trash directory
trash

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

.idea

# Ignore backup files.
*-backup.json
backup/*
tmp/*
.DS_Store
72 changes: 72 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# *********************************************************************
# ___ ___ ___ ___ ___
# / __| /_\ \ / /_\ / __| __|
# \__ \/ _ \ V / _ \ (_ | _|
# |___/_/_\_\_/_/_\_\___|___| ___ ___ ___
# / __|/ _ \| __|_ _\ \ / /_\ | _ \ __|
# \__ \ (_) | _| | | \ \/\/ / _ \| / _|
# |___/\___/|_| |_| \_/\_/_/ \_\_|_\___|
#
# -------------------------------------------------------------------
# PORTAINER-BACKUP
# https://github.com/SavageSoftware/portainer-backup
# -------------------------------------------------------------------
#
# This Dockerfile creates an Alpine-based Linux docker image
# with the PORTAINER-BACKUP utility installed. This is useful
# for creating a Docker container to perform scheduled backups
# of a portainer server.
#
# *********************************************************************
# COPYRIGHT SAVAGESOFTWARE,LLC, @ 2022, ALL RIGHTS RESERVED
# *********************************************************************
FROM node:lts-alpine

# IMAGE ARGUMENTS PASSED IN FROM BUILDER
ARG TARGETARCH
ARG BUILDDATE
ARG BUILDVERSION

# PROVIDE IMAGE LABLES
LABEL "com.example.vendor"="ACME Incorporated"
LABEL vendor="Savage Software, LLC"
LABEL maintainer="Robert Savage"
LABEL version="$VERSION"
LABEL description="Utility for scripting or scheduling scheduled backups for Portainer"
LABEL url="https://github.com/SavageSoftware/portainer-backup"
LABEL org.label-schema.schema-version="$VERSION"
LABEL org.label-schema.build-date="$BUILDDATE"
LABEL org.label-schema.name="savagesoftware/portainer-backup"
LABEL org.label-schema.description="Utility for scripting or scheduling scheduled backups for Portainer"
LABEL org.label-schema.url="https://github.com/SavageSoftware/portainer-backup"
LABEL org.label-schema.vcs-url="https://github.com/SavageSoftware/portainer-backup.git"
LABEL org.label-schema.vendor="Savage Software, LLC"
LABEL org.label-schema.version=$VERSION
LABEL org.label-schema.docker.cmd="docker run -it --rm --name portainer-backup --volume $PWD/backup:/backup savagesoftware/portainer-backup:latest backup"

# INSTALL ADDITIONAL IMAGE DEPENDENCIES AND COPY APPLICATION TO IMAGE
RUN apk update && apk add --no-cache tzdata
RUN mkdir -p /app
COPY app/package.json /app
COPY app/*.js /app
WORKDIR /app
VOLUME "/backup"
RUN npm install --silent

# DEFAULT ENV VARIABLE VALUES
ENV TZ="America/New_York"
ENV PORTAINER_BACKUP_URL="http://portainer:9000"
ENV PORTAINER_BACKUP_TOKEN=""
ENV PORTAINER_BACKUP_DIRECTORY="/backup"
ENV PORTAINER_BACKUP_FILENAME="/portainer-backup.tar.gz"
ENV PORTAINER_BACKUP_OVERWRITE=false
ENV PORTAINER_BACKUP_CONCISE=false
ENV PORTAINER_BACKUP_DEBUG=false
ENV PORTAINER_BACKUP_DRYRUN=false
ENV PORTAINER_BACKUP_STACKS=false

# NODEJS RUNNING THIS APPLICATION IS THE ENTRYPOINT
ENTRYPOINT [ "/usr/local/bin/node", "index.js" ]

# DEFAULT COMMAND (if none provided)
CMD ["schedule"]
86 changes: 86 additions & 0 deletions app/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* -------------------------------------------------------------------
* ___ ___ ___ ___ ___
* / __| /_\ \ / /_\ / __| __|
* \__ \/ _ \ V / _ \ (_ | _|
* |___/_/_\_\_/_/_\_\___|___| ___ ___ ___
* / __|/ _ \| __|_ _\ \ / /_\ | _ \ __|
* \__ \ (_) | _| | | \ \/\/ / _ \| / _|
* |___/\___/|_| |_| \_/\_/_/ \_\_|_\___|
*
* -------------------------------------------------------------------
* COPYRIGHT SAVAGESOFTWARE,LLC, @ 2022, ALL RIGHTS RESERVED
* https://github.com/SavageSoftware/portainer-backup
* -------------------------------------------------------------------
*/

// import libraries
import path from 'node:path';
import sanitize from 'sanitize-filename';
import Util from './util.js'

export class Configuration {

/**
* Default Constructor
*
* Initialize configuration settings with default values
* or values defined via environment variables.
*/
constructor() {
// initialize configuration settings using envrironment variables
this.portainer = {
token: process.env.PORTAINER_BACKUP_TOKEN || "",
baseUrl: process.env.PORTAINER_BACKUP_URL || "http://127.0.0.1:9000",
ignoreVersion: process.env.PORTAINER_BACKUP_IGNORE_VERSION || false
};
this.backup = {
directory: process.env.PORTAINER_BACKUP_DIRECTORY || "backup",
filename: sanitize(process.env.PORTAINER_BACKUP_FILENAME || "portainer-backup.tar.gz"),
file: "", /* INITIALIZED BELOW */
password: process.env.PORTAINER_BACKUP_PASSWORD || "",
stacks: Util.evalBool(process.env.PORTAINER_BACKUP_STACKS),
overwrite: Util.evalBool(process.env.PORTAINER_BACKUP_OVERWRITE),
schedule: process.env.PORTAINER_BACKUP_SCHEDULE || "0 0 0 * * * *"
};
this.dryRun = Util.evalBool(process.env.PORTAINER_BACKUP_DRYRUN);
this.debug = Util.evalBool(process.env.PORTAINER_BACKUP_DEBUG);
this.quiet = Util.evalBool(process.env.PORTAINER_BACKUP_QUIET);
this.json = Util.evalBool(process.env.PORTAINER_BACKUP_JSON);
this.concise = Util.evalBool(process.env.PORTAINER_BACKUP_CONCISE);

// construct backup file path using backup directory and backup filename
this.backup.file = path.resolve(this.backup.directory, this.backup.filename);
}

/**
* override configuration settings if any configurtation
* arguments have been explicitly provided via the command
* line arguments
*
* @param {*} args
*/
process(args){

// check arguments for valid settings; override config settings
if(args.token) this.portainer.token = args.token;
if(args.url) this.portainer.baseUrl = args.url;
if(args.ignoreVersion) this.portainer.ignoreVersion = Util.evalBool(args.ignoreVersion);
if(args.directory) this.backup.directory = args.directory;
if(args.filename) this.backup.filename = args.filename;
if(args.password) this.backup.password = args.password;
if(args.overwrite) this.backup.overwrite = Util.evalBool(args.overwrite);
if(args.stacks) this.backup.stacks = Util.evalBool(args.stacks);
if(args.schedule) this.backup.schedule = args.schedule;
if(args.dryrun) this.dryRun = Util.evalBool(args.dryrun);
if(args.debug) this.debug = Util.evalBool(args.debug);
if(args.quiet) this.quiet = Util.evalBool(args.quiet);
if(args.json) this.json = Util.evalBool(args.json);
if(args.concise) this.concise = Util.evalBool(args.concise);

// construct backup file path using backup directory and backup filename
this.backup.file = path.resolve(this.backup.directory, this.backup.filename);
this.backup.directory = path.resolve(this.backup.directory);
}
}

Loading

0 comments on commit 770b197

Please sign in to comment.