Skip to content
Snippets Groups Projects
Select Git revision
  • abe9a81c5f9647e96a9a9af777c373fbf1fff6cf
  • main default protected
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
36 results

RELEASE_GUIDELINES.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    backup.sh 3.16 KiB
    #!/bin/bash
    #
    # ** header v3.0
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2018 Research Group Biomedical Physics,
    # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    #
    # ** end header
    #
    
    # Dump a database with all procedures, permissions, structure and data
    
    # The directory which the dump is to be stored to. Do not change it here. Use
    # the --backupdir=./my/dir/ option or an environment variable instead.
    BACKUPDIR="${BACKUPDIR:-./backup}"
    # Iff this (environment) variable is "true" as lower-case, then this script also
    # outputs a machine readable status report.  The variable can also be set by
    # giving the `--yaml` command line option.
    YAML="${YAML:-false}"
    
    PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be stored to. (Defaults to ./backup,\n\tcan also be set as an environment variable.)\n"
    
    # YAML string templates #######################################################
    
    YAMLFAIL=$(cat << "EOF"
    #### YAML ####
    error:
      - code: $error_code
      - message: $error_message
    #### YAML END ####
    EOF
            )
    
    YAMLSUCCESS=$(cat << "EOF"
    #### YAML ####
    error:
      - code: 0
      - message: Backup successfully created
    backup:
      - location: $file_location
      - date: $date
    #### YAML END ####
    EOF
            )
    
    # Config and command line parameter loading ###################################
    
    . .config
    
    # load useful stuff - parses the commandline parameters and so on...
    . patches/utils/patch_header.sh
    
    echo "BACKUPDIR: $BACKUPDIR"
    echo "YAML: $YAML"
    
    function backup() {
        NARG_NAME="$1"
        NARG_FILE="$2"
        shift 2
        echo $MYSQLDUMP_CMD
    	# parameters: connection, database, outfile
    	if [ -e "$NARG_FILE" ]; then
    		failure "dumpfile already exists."
    	fi
        echo "Dumping database $NARG_NAME to $NARG_FILE ... "
    	$CMD_MYSQL_DUMP $MYSQL_CONNECTION_NO_DB $* --opt --default-character-set=utf8 --routines $NARG_NAME > $NARG_FILE
    	success
    }
    
    # Prints a YAML failure message, if YAML is true.
    #
    # Arguments:
    # - $1  Error code, integer > 0
    # - $2  Error message
    function yaml_fail() {
        err_code="$1"
        err_msg="$2"
        local yaml="${YAML_FAIL/\$err_code/$err_code}"
        yaml="${yaml/\$err_msg/$err_msg}"
        echo "$yaml"
    }
    
    # Prints a YAML success message, if YAML is true.
    function yaml_success() {
    
    }
    
    ##test dump file exists
    #touch dumpfile.tmp
    #backup 0 1 2 "dumpfile.tmp"
    #rm dumpfile.tmp
    
    # create backup dir if not exists
    [ -d "$BACKUPDIR" ] || mkdir "$BACKUPDIR" || 
    
    DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g')
    BACKUPFILE=${BACKUPDIR}/${DATABASE_NAME}.${DATE}.dump.sql
    backup $DATABASE_NAME $BACKUPFILE