Initial commit
This commit is contained in:
71
Backup/automaticBackup.sh
Normal file
71
Backup/automaticBackup.sh
Normal file
@ -0,0 +1,71 @@
|
||||
# =============================================================================
|
||||
# automaticBackup.sh
|
||||
#
|
||||
# Automatic, configurable, optional-SFTP backup script.
|
||||
#
|
||||
# Copyright (c) 2025 VELENDEU, eetnaviation
|
||||
#
|
||||
# https://velend.eu/
|
||||
# https://git.velend.eu/eetnaviation/shscripts
|
||||
#
|
||||
# All rights reserved unless otherwise stated.
|
||||
#
|
||||
# Permission is hereby denied to copy, modify, distribute, sublicense,
|
||||
# or sell copies of this software without explicit prior written consent.
|
||||
#
|
||||
# All dependency trademarks and names if included are subject to copyright
|
||||
# of their respective owners.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
# =============================================================================
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
##################### BEGIN USER CONFIGURABLE PART #####################
|
||||
|
||||
BACKUP_PATHS="" # Choose directories you want to backup separated by spaces. Example: Backup /home and /var/www would be "/home /var/www"
|
||||
BACKUP_DESTINATION="/backup" # Default /backup, changes the backup destination. This is where your local backups are stored.
|
||||
|
||||
ENABLE_SFTP_BACKUP="false" # Default false, enables/disables SFTP backup sync.
|
||||
DELETE_LOCAL_BACKUP_UPON_SUCCESSFUL_SFTP_UPLOAD="true" # Default true, enables/disables deleting local backup after successful upload to sftp server.
|
||||
SFTP_USER="" # Enter your SFTP user here.
|
||||
SFTP_HOST="" # Enter your SFTP server IP or domain name here.
|
||||
SFTP_PASSWORD="" # Enter your SFTP user password here.
|
||||
SFTP_REMOTE_DIRECTORY="" # Enter your SFTP remote directory here.
|
||||
|
||||
###################### END USER CONFIGURABLE PART ######################
|
||||
|
||||
DATE=$(date +%Y-%m-%d)
|
||||
HOSTNAME=$(HOSTNAME -s)
|
||||
ARCHIVE_FILE_NAME="$HOSTNAME-$DATE.tgz"
|
||||
LOCAL_FILE="$BACKUP_DESTINATION/$ARCHIVE_FILE_NAME"
|
||||
|
||||
# Local backup part.
|
||||
echo "Starting local backup..."
|
||||
mkdir -p "$BACKUP_DESTINATION"
|
||||
tar czf "$BACKUP_DESTINATION/$ARCHIVE_FILE_NAME" $BACKUP_PATHS
|
||||
echo "Finished local backup!"
|
||||
ls -aril "$BACKUP_DESTINATION"
|
||||
|
||||
# If enabled sync backup to SFTP server.
|
||||
if [ "$ENABLE_SFTP_BACKUP" = "true" ]; then
|
||||
lftp -u "$SFTP_USER,$SFTP_PASSWORD" sftp://$SFTP_HOST <<EOF
|
||||
put "$LOCAL_FILE" -o "$SFTP_REMOTE_DIRECTORY/$(basename $LOCAL_FILE)"
|
||||
quit
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Tell user SFTP sync is finished
|
||||
echo "Uploaded backup to destination SFTP server."
|
||||
|
||||
# Delete local file to save space, this can be enabled or disabled with DELETE_LOCAL_BACKUP_UPON_SUCCESSFUL_SFTP_UPLOAD.
|
||||
if [ "$DELETE_LOCAL_BACKUP_UPON_SUCCESSFUL_SFTP_UPLOAD" = "true" ]; then
|
||||
rm -f "$BACKUP_DESTINATION/$ARCHIVE_FILE_NAME"
|
||||
echo "Deleted local copy of backup successfully."
|
||||
fi
|
Reference in New Issue
Block a user