Skip to content

Instantly share code, notes, and snippets.

@Rajdave69
Created June 25, 2023 06:18
Show Gist options
  • Save Rajdave69/e58266bc74c631df88ff387db5918f7e to your computer and use it in GitHub Desktop.
Save Rajdave69/e58266bc74c631df88ff387db5918f7e to your computer and use it in GitHub Desktop.
This is a simple script that can backup a directory of a server to another server with SFTP.
#!/bin/sh
# Put FTP server details here
SERVER="" # server ip/fdqn
USERNAME=""
PASSWORD=""
# local directory containing source backup files
SOURCEFILES="/var/lib/pterodactyl/volumes/"
# temporary tar.gz file path
TARGZFILE="/var/lib/pterodactyl/volumes/volumes.tar.gz"
# remote server directory path in which backup needs to be put in
BACKUPDIRECTORY="/mnt/A/server-backups/node-60/"
# create a tar.gz archive of the source files
tar -czf "$TARGZFILE" -C "$(dirname "$SOURCEFILES")" "$(basename "$SOURCEFILES")"
# login to remote server using lftp
lftp "sftp://$USERNAME:$PASSWORD@$SERVER$BACKUPDIRECTORY" <<EOF
put "$TARGZFILE"
quit
EOF
# remove the temporary tar.gz file
rm "$TARGZFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment