sftpbackup: Initial version of role
This commit is contained in:
parent
06f4645127
commit
64e2b45d6f
3 changed files with 39 additions and 0 deletions
29
roles/sftpbackup/files/backup-sftp.sh
Normal file
29
roles/sftpbackup/files/backup-sftp.sh
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -u
|
||||||
|
umas 077
|
||||||
|
|
||||||
|
TARGET="/export/backup"
|
||||||
|
CONFIG="/etc/rclone/rclone.conf"
|
||||||
|
LOGDIR="/var/log/rclone"
|
||||||
|
RCLONE="/usr/local/bin/rclone"
|
||||||
|
|
||||||
|
timestamp="$(date %Y%m%d)"
|
||||||
|
|
||||||
|
if [ ! -d "$TARGET" ]; then
|
||||||
|
echo "ERR: Destination directory '${TARGET}' does not exist" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for host in $("$RCLONE" --config "$CONFIG" listremotes | tr -d ":") ; do
|
||||||
|
fqdn="$("$RCLONE" --config "$CONFIG" config show "$host" | \
|
||||||
|
awk '{ if ($1 == "host") print $3 }')"
|
||||||
|
if [ ! -d "${TARGET}/${fqdn}" ]; then
|
||||||
|
mkdir "${TARGET}/${fqdn}"
|
||||||
|
fi
|
||||||
|
log="${LOGDIR}/${fqdn}.${timestamp}.log"
|
||||||
|
if ! "$RCLONE" --config "$CONFIG" --log-file "$log" --log-level INFO \
|
||||||
|
sync "${host}:/" "${TARGET}/${fqdn}/"; then
|
||||||
|
cat "$log"
|
||||||
|
fi
|
||||||
|
done
|
3
roles/sftpbackup/meta/main.yml
Normal file
3
roles/sftpbackup/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- {role: ssh_known_hosts}
|
7
roles/sftpbackup/tasks/main.yml
Normal file
7
roles/sftpbackup/tasks/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
- import_role:
|
||||||
|
name: rclone
|
||||||
|
vars:
|
||||||
|
hostgroup: sftpbackup
|
||||||
|
remote_user: backup
|
||||||
|
destination: /export/backup
|
Loading…
Add table
Add a link
Reference in a new issue