Initial Draft
This commit is contained in:
parent
60ef427e8a
commit
e0a8bf8d3f
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#/////////////////////////////////////////////////////
|
||||
#
|
||||
#
|
||||
# BORG BACKUP
|
||||
#
|
||||
#
|
||||
#/////////////////////////////////////////////////////
|
||||
|
||||
# NOTE: Make sure the repository is initialize with borg init
|
||||
# first before creating a backup!
|
||||
|
||||
# NOTE: Make sure the expect command is installed on the system!
|
||||
|
||||
# NOTE: All these variables can be placed in /etc/borgbackup.conf
|
||||
|
||||
# Path to repository
|
||||
# Example: user@server:/path/on/remote
|
||||
# NOTE: Make sure it ends with / or face the consquences!
|
||||
REPOSITORY=''
|
||||
|
||||
# Passphrase for borg backup.
|
||||
# NOTE: If you don't want to include the passphrase here.
|
||||
# You can include it in /etc/borgbackup.conf
|
||||
PASSPHRASE=''
|
||||
|
||||
# Source directory to backup
|
||||
# Example: /path/to/backup
|
||||
SOURCE='/'
|
||||
|
||||
# Exclude paths from backup.
|
||||
# Example: --exclude /exclude1 --exclude /exclude2
|
||||
EXCLUDES=''
|
||||
|
||||
# Run commands before backup
|
||||
# Example: systemctl stop mysqld
|
||||
PREHOOK=""
|
||||
|
||||
# Run commands after backup
|
||||
# Example: systemctl start mysqld
|
||||
POSTHOOK=""
|
||||
|
||||
|
||||
|
||||
# DO NOT MODIFY ANY CODE BELOW THIS LINE
|
||||
|
||||
if test -f /etc/borgbackup.conf; then
|
||||
source /etc/borgbackup.conf
|
||||
fi
|
||||
|
||||
# Define the expect script in a variable
|
||||
expect_script=$(cat <<END_EXPECT
|
||||
#!/usr/bin/expect -f
|
||||
|
||||
# Set the timeout for waiting
|
||||
set timeout 30
|
||||
|
||||
# Set the passphrase
|
||||
set _passphrase "$PASSPHRASE"
|
||||
|
||||
# Spawn the command
|
||||
spawn /bin/borg create --stats -v $REPOSITORY::'{hostname}-{now:%Y-%m-%d}' $SOURCE $EXCLUDES
|
||||
|
||||
# Expect the passphrase prompt and send the passphrase
|
||||
expect "Enter passphrase for key*"
|
||||
send "\$_passphrase\r"
|
||||
|
||||
# Wait for the command to finish
|
||||
expect eof
|
||||
END_EXPECT
|
||||
)
|
||||
|
||||
eval $PREHOOK
|
||||
|
||||
# Save the expect script to a temporary file
|
||||
expect_script_file=$(mktemp)
|
||||
echo "$expect_script" > "$expect_script_file"
|
||||
|
||||
# Make the temporary expect script executable
|
||||
chmod +x "$expect_script_file"
|
||||
|
||||
# Execute the expect script
|
||||
$expect_script_file
|
||||
|
||||
# Clean up the temporary expect script
|
||||
rm -f "$expect_script_file"
|
||||
|
||||
eval $POSTHOOK
|
Loading…
Reference in New Issue