diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..5c1618d --- /dev/null +++ b/README.adoc @@ -0,0 +1 @@ += Android Borgmatic Setup diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..138689c --- /dev/null +++ b/config.yaml @@ -0,0 +1,241 @@ +# Where to look for files to backup, and where to store those backups. See +# https://borgbackup.readthedocs.io/en/stable/quickstart.html and +# https://borgbackup.readthedocs.io/en/stable/usage.html#borg-create for details. +location: + # List of source directories to backup (required). Globs and tildes are expanded. + source_directories: + - /storage/emulated/0/ + + # Paths to local or remote repositories (required). Tildes are expanded. Multiple + # repositories are backed up to in sequence. See ssh_command for SSH options like + # identity file or port. + repositories: + - REPO_PLACEHOLDER + + # Stay in same file system (do not cross mount points). Defaults to false. + one_file_system: CROSS_FILESYSTEM_PLACEHOLDER + + # Only store/extract numeric user and group identifiers. Defaults to false. + #numeric_owner: true + + # Store atime into archive. Defaults to true. + #atime: false + + # Store ctime into archive. Defaults to true. + #ctime: false + + # Store birthtime (creation date) into archive. Defaults to true. + #birthtime: false + + # Use Borg's --read-special flag to allow backup of block and other special + # devices. Use with caution, as it will lead to problems if used when + # backing up special devices such as /dev/zero. Defaults to false. + #read_special: false + + # Record bsdflags (e.g. NODUMP, IMMUTABLE) in archive. Defaults to true. + #bsd_flags: true + + # Mode in which to operate the files cache. See + # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description for + # details. Defaults to "ctime,size,inode". + #files_cache: ctime,size,inode + + # Alternate Borg local executable. Defaults to "borg". + #local_path: borg1 + + # Alternate Borg remote executable. Defaults to "borg". + remote_path: REMOTE_PATH_PLACEHOLDER + + # Any paths matching these patterns are included/excluded from backups. Globs are + # expanded. (Tildes are not.) Note that Borg considers this option experimental. + # See the output of "borg help patterns" for more details. Quote any value if it + # contains leading punctuation, so it parses correctly. + #patterns: + # - R / + # - '- /home/*/.cache' + # - + /home/susan + # - '- /home/*' + + # Read include/exclude patterns from one or more separate named files, one pattern + # per line. Note that Borg considers this option experimental. See the output of + # "borg help patterns" for more details. + #patterns_from: + # - /etc/borgmatic/patterns + + # Any paths matching these patterns are excluded from backups. Globs and tildes + # are expanded. See the output of "borg help patterns" for more details. + #exclude_patterns: + # - '*.pyc' + # - ~/*/.cache + # - /etc/ssl + + # Read exclude patterns from one or more separate named files, one pattern per + # line. See the output of "borg help patterns" for more details. + #exclude_from: + # - /etc/borgmatic/excludes + + # Exclude directories that contain a CACHEDIR.TAG file. See + # http://www.brynosaurus.com/cachedir/spec.html for details. Defaults to false. + exclude_caches: true + + # Exclude directories that contain a file with the given filename. Defaults to not + # set. + #exclude_if_present: .nobackup + +# Repository storage options. See +# https://borgbackup.readthedocs.io/en/stable/usage.html#borg-create and +# https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for +# details. +storage: + # The standard output of this command is used to unlock the encryption key. Only + # use on repositories that were initialized with passcommand/repokey encryption. + # Note that if both encryption_passcommand and encryption_passphrase are set, + # then encryption_passphrase takes precedence. Defaults to not set. + #encryption_passcommand: secret-tool lookup borg-repository repo-name + + # Passphrase to unlock the encryption key with. Only use on repositories that were + # initialized with passphrase/repokey encryption. Quote the value if it contains + # punctuation, so it parses correctly. And backslash any quote or backslash + # literals as well. Defaults to not set. + encryption_passphrase: "PASSWORD_PLACEHOLDER" + + # Number of seconds between each checkpoint during a long-running backup. See + # https://borgbackup.readthedocs.io/en/stable/faq.html#if-a-backup-stops-mid-way-does-the-already-backed-up-data-stay-there + # for details. Defaults to checkpoints every 1800 seconds (30 minutes). + #checkpoint_interval: 1800 + + # Specify the parameters passed to then chunker (CHUNK_MIN_EXP, CHUNK_MAX_EXP, + # HASH_MASK_BITS, HASH_WINDOW_SIZE). See https://borgbackup.readthedocs.io/en/stable/internals.html + # for details. Defaults to "19,23,21,4095". + #chunker_params: 19,23,21,4095 + + # Type of compression to use when creating archives. See + # https://borgbackup.readthedocs.org/en/stable/usage.html#borg-create for details. + # Defaults to "lz4". + #compression: lz4 + + # Remote network upload rate limit in kiBytes/second. Defaults to unlimited. + #remote_rate_limit: 100 + + # Command to use instead of "ssh". This can be used to specify ssh options. + # Defaults to not set. + #ssh_command: ssh -i /path/to/private/key + + # Base path used for various Borg directories. Defaults to $HOME, ~$USER, or ~. + # See https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for details. + #borg_base_directory: /path/to/base + + # Path for Borg configuration files. Defaults to $borg_base_directory/.config/borg + #borg_config_directory: /path/to/base/config + + # Path for Borg cache files. Defaults to $borg_base_directory/.cache/borg + #borg_cache_directory: /path/to/base/cache + + # Path for Borg security and encryption nonce files. Defaults to $borg_base_directory/.config/borg/security + #borg_security_directory: /path/to/base/config/security + + # Path for Borg encryption key files. Defaults to $borg_base_directory/.config/borg/keys + #borg_keys_directory: /path/to/base/config/keys + + # Umask to be used for borg create. Defaults to 0077. + #umask: 0077 + + # Maximum seconds to wait for acquiring a repository/cache lock. Defaults to 1. + #lock_wait: 5 + + # Name of the archive. Borg placeholders can be used. See the output of + # "borg help placeholders" for details. Defaults to + # "{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}". If you specify this option, you must + # also specify a prefix in the retention section to avoid accidental pruning of + # archives with a different archive name format. And you should also specify a + # prefix in the consistency section as well. + #archive_name_format: '{hostname}-documents-{now}' + +# Retention policy for how many backups to keep in each category. See +# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details. +# At least one of the "keep" options is required for pruning to work. See +# https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/ +# if you'd like to skip pruning entirely. +retention: + # Keep all archives within this time interval. + #keep_within: 3H + + # Number of secondly archives to keep. + #keep_secondly: 60 + + # Number of minutely archives to keep. + #keep_minutely: 60 + + # Number of hourly archives to keep. + #keep_hourly: 24 + + # Number of daily archives to keep. + keep_daily: 7 + + # Number of weekly archives to keep. + #keep_weekly: 4 + + # Number of monthly archives to keep. + #keep_monthly: 6 + + # Number of yearly archives to keep. + #keep_yearly: 1 + + # When pruning, only consider archive names starting with this prefix. + # Borg placeholders can be used. See the output of "borg help placeholders" for + # details. Defaults to "{hostname}-". + #prefix: sourcehostname + +# Consistency checks to run after backups. See +# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and +# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-extract for details. +#consistency: + # List of one or more consistency checks to run: "repository", "archives", and/or + # "extract". Defaults to "repository" and "archives". Set to "disabled" to disable + # all consistency checks. "repository" checks the consistency of the repository, + # "archive" checks all of the archives, and "extract" does an extraction dry-run + # of the most recent archive. + #checks: + # - repository + # - archives + + # Paths to a subset of the repositories in the location section on which to run + # consistency checks. Handy in case some of your repositories are very large, and + # so running consistency checks on them would take too long. Defaults to running + # consistency checks on all repositories configured in the location section. + #check_repositories: + # - user@backupserver:sourcehostname.borg + + # Restrict the number of checked archives to the last n. Applies only to the "archives" check. Defaults to checking all archives. + #check_last: 3 + + # When performing the "archives" check, only consider archive names starting with + # this prefix. Borg placeholders can be used. See the output of + # "borg help placeholders" for details. Defaults to "{hostname}-". + #prefix: sourcehostname + +# Options for customizing borgmatic's own output and logging. +#output: + # Apply color to console output. Can be overridden with --no-color command-line + # flag. Defaults to true. + #color: false + +# Shell commands or scripts to execute before and after a backup or if an error has occurred. +# IMPORTANT: All provided commands and scripts are executed with user permissions of borgmatic. +# Do not forget to set secure permissions on this file as well as on any script listed (chmod 0700) to +# prevent potential shell injection or privilege escalation. +#hooks: + # List of one or more shell commands or scripts to execute before creating a backup. + #before_backup: + # - echo "Starting a backup job." + + # List of one or more shell commands or scripts to execute after creating a backup. + #after_backup: + # - echo "Backup created." + + # List of one or more shell commands or scripts to execute in case an exception has occurred. + #on_error: + # - echo "Error while creating a backup." + + # Umask used when executing hooks. Defaults to the umask that borgmatic is run with. + #umask: 0077 diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..c370996 --- /dev/null +++ b/init.sh @@ -0,0 +1,91 @@ +#!/bin/bash +{ +# For later: +# /data/data/com.termux/files/usr/libexec/termux-api JobScheduler --ei job_id 1 --ei period_ms 900000 --ez charging true -es script $HOME/test.sh +set -ex +SCRIPT_DIR="$(cd "${BASH_SOURCE%/*}"; pwd)" +DEBS_URL="https://linx.austenwares.com/selif/z4v8ou3s.tar" +DEBS_FNAME="${DEBS_URL##*/}" +DEBS_HASH="033a276609c8ae55062c991a5062282df73e395a5746ab709af982780cb56491 $DEBS_FNAME" +die() { + echo "ERROR: $1" >&2 + exit 1 +} +install_requirements() { + apt-get update + apt-get upgrade -y + apt-get install -y python screen wget + + if ! command -v borgmatic 2>/dev/null || ! command -v borg 2>/dev/null; then + get_debs + install_debs + fi +} +get_debs() { + wget "$DEBS_URL" -O "$DEBS_FNAME" + sha256sum -c <(echo "$DEBS_HASH") || die "Download hash mismatch" +} +install_debs() { + tar -xf "$DEBS_FNAME" + pushd debs + dpkg -i *.deb || : + apt-get -f install + popd +} +replace () { + FILE="$1" + PLACEHOLDER="${2}_PLACEHOLDER" + PROMT="$3" + DEFAULT="$4" + printf "$PROMT [$DEFAULT] > " + read -r RESP + if [[ -z "$RESP" ]]; then + VALUE="$DEFAULT" + else + VALUE="$RESP" + fi + + # Do the replacement + sed -i "$FILE" -e "s/${PLACEHOLDER//\//\\/}/${VALUE//\//\\/}/g" +} +install_templates() { + echo "Installling templates" + BORGMATIC_CONFIG_FILE="$HOME/.config/borgmatic/config.yaml" + if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_CONFIG_FILE" ]]; then + mkdir -p "$HOME/.config/borgmatic" + cp "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" + + set +x + replace "$BORGMATIC_CONFIG_FILE" REPO "What is your repository?" "user@files:$(hostname)" + replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "Cross filesystem?" "true" + replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "Remote borg command?" "borg1" + replace "$BORGMATIC_CONFIG_FILE" PASSWORD "Encryption password?" "$(tr -dc "+|~=[];:\-/.,<>?'#@!$%^&*(){}_A-Z-a-z-0-9" < /dev/urandom | head -c32)" + set -x + + echo "Config file differences:" + diff -Nu "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" || : + fi +} + +install_complete() { + cat <<-EOF + + + Installation complete! + To setup your repository, run: + borgmatic init -e repokey-blake2 + To make a backup, run: + borgmatic --verbosity 2 + + + EOF +} + +cd "/data/data/com.termux/files/usr/tmp/tmp.k5RE3ly9Hm" +# cd "$(mktemp -d)" +install_requirements +# get_debs +# install_debs +install_templates "$1" +install_complete +}