Skip to content

Writing pre-scripts and post-scripts: update missing information #23

Open
@xezpeleta

Description

@xezpeleta

Currently the following environment variables are documented:

ELKARBACKUP_LEVEL
ELKARBACKUP_EVENT
ELKARBACKUP_URL
ELKARBACKUP_ID
ELKARBACKUP_PATH
ELKARBACKUP_STATUS

The following envars are missing in the script creation section:

ELKARBACKUP_CLIENT_NAME: client name
ELKARBACKUP_JOB_NAME: job name (empty in client)
ELKARBACKUP_OWNER_EMAIL: job owner's email address (empty in client)
ELKARBACKUP_RECIPIENT_LIST: job recipients email addresses (empty in client)
ELKARBACKUP_CLIENT_TOTAL_SIZE: current client disk usage (in KB)
ELKARBACKUP_JOB_TOTAL_SIZE: current job disk usage (in KB, empty in client)
ELKARBACKUP_JOB_RUN_SIZE: data size backed up this run (in KB, empty in client)
ELKARBACKUP_CLIENT_STARTTIME: client backup start timestamp (only available in client scripts)
ELKARBACKUP_CLIENT_ENDTIME: client backup end timestamp (only available in post client scripts)
ELKARBACKUP_JOB_STARTTIME: job backup start timestamp (only available in job scripts)
ELKARBACKUP_JOB_ENDTIME: job backup end timestamp (only available in post job scripts)
ELKARBACKUP_SSH_ARGS: advanced arguments for ssh conection

We also could make it clear that the scripts are executed in the Elkarbackup server. If you need to run some code in the client, you need to do it by yourself in your script.

In that case, the following code might be helpful (change the ssh privkey path if you're on a Docker container):

#ELKARBACKUP_URL = user@serverip:/path
URL=`echo $ELKARBACKUP_URL | cut -d ":" -f1`    # user@serverip
USER="${URL%@*}"                                # user
HOST="${URL#*@}"                                # host
SSHPARAMS="-i /var/lib/elkarbackup/.ssh/id_rsa -o StrictHostKeyChecking=no  $ELKARBACKUP_SSH_ARGS"

# Run a commmand via SSH and return the exit code
function ssh_exec {
    cmd="$1"
    output="$(ssh $SSHPARAMS $USER@$HOST $cmd && echo $?)"
    return $output
}

# Run a command via SSH and return the output
function ssh_exec_output {
    cmd="$1"
    output="$(ssh $SSHPARAMS $USER@$HOST $cmd)"
    echo "$output"
}

More info: https://github.com/elkarbackup/elkarbackup-scripts/blob/master/backup-permissions/backup-permissions.sh

Refere to https://github.com/elkarbackup/elkarbackup-scripts for more examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions