mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-12-23 21:20:41 +01:00
30 lines
764 B
Bash
30 lines
764 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# /etc/cron.weekly/backup-to-minio
|
||
|
|
||
|
TEMP_DIR=$(mktemp -d || echo "Failed to make temp dir"; exit 1)
|
||
|
chmod 700 "${TEMP_DIR}"
|
||
|
trap 'rm -rf "${TEMP_DIR}" ; exit 0' 0 1 2 3 15
|
||
|
|
||
|
while read -r line; do
|
||
|
rsync -aAX "$line" "${TEMP_DIR}" ;
|
||
|
done </etc/rsync-includes.txt
|
||
|
|
||
|
UNPRIV_USER=$(grep "1000" /etc/passwd | awk -F: '{print $1}')
|
||
|
chown -R "$UNPRIV_USER":"$UNPRIV_USER" "${TEMP_DIR}"
|
||
|
|
||
|
declare -i NUM_TX
|
||
|
NUM_TX=$(getconf _NPROCESSORS_ONLN)/2
|
||
|
|
||
|
if ! test -f "/home/${UNPRIV_USER}/.config/rclone/rclone.conf"; then
|
||
|
echo "Rclone config not found. Setup rclone first."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if ! sudo -u "$UNPRIV_USER" rclone copy --quiet --transfers="$NUM_TX" "${TEMP_DIR}" "minio:$(hostname)"; then
|
||
|
echo "Error running rclone"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
exit 0
|