Compare commits
No commits in common. "d555f919beefd91f0ea7492544b7a645e6f17ce3" and "48b0335071f7a4dcb074a63f80e8ebfa6a6c00e8" have entirely different histories.
d555f919be
...
48b0335071
@ -1,12 +1,12 @@
|
|||||||
## The playbook first runs the 'backup.yml' from each role
|
## The playbook first runs the 'backup.yml' from each role
|
||||||
- name: create the /backup-dirs file # this also runs on main in case someone doesn't run the backup.yml
|
- name: create the /backup-dirs file
|
||||||
file:
|
file:
|
||||||
path: "/backup-dirs"
|
path: "/backup-dirs"
|
||||||
state: "touch"
|
state: "touch"
|
||||||
mode: "0400"
|
mode: "0400"
|
||||||
changed_when: "true" # we always want ti give roles a chance to register dirs
|
changed_when: "true" # we always want ti give roles a chance to register dirs
|
||||||
|
|
||||||
- name: Ensure file contains lines from array # this also runs on main in case someone doesn't run the backup.yml
|
- name: Ensure file contains lines from array
|
||||||
lineinfile:
|
lineinfile:
|
||||||
path: /backup-dirs
|
path: /backup-dirs
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
|
|||||||
@ -1,17 +1,5 @@
|
|||||||
- name: create the /backup-dirs file # this also runs on main in case someone doesn't run the backup.yml
|
- debug:
|
||||||
file:
|
var: group_names
|
||||||
path: "/backup-dirs"
|
|
||||||
state: "touch"
|
|
||||||
mode: "0400"
|
|
||||||
changed_when: "true" # we always want ti give roles a chance to register dirs
|
|
||||||
|
|
||||||
- name: Ensure file contains lines from array # this also runs on main in case someone doesn't run the backup.yml
|
|
||||||
lineinfile:
|
|
||||||
path: /backup-dirs
|
|
||||||
line: "{{ item }}"
|
|
||||||
create: yes
|
|
||||||
state: present
|
|
||||||
loop: "{{ extra_backup_paths }}"
|
|
||||||
|
|
||||||
- name: make sure restic is installed
|
- name: make sure restic is installed
|
||||||
apt: state=latest pkg=restic
|
apt: state=latest pkg=restic
|
||||||
|
|||||||
@ -5,53 +5,51 @@ original_dir=$(pwd)
|
|||||||
source ./vars.sh
|
source ./vars.sh
|
||||||
cd "$original_dir"
|
cd "$original_dir"
|
||||||
|
|
||||||
(
|
./mount.sh &
|
||||||
./mount.sh &
|
RESTIC_PID=$!
|
||||||
RESTIC_PID=$!
|
|
||||||
|
|
||||||
MOUNT_DIR="/mnt/restic"
|
MOUNT_DIR="/mnt/restic"
|
||||||
|
|
||||||
# Wait until the directory exists
|
# Wait until the directory exists
|
||||||
while [ ! -d "$MOUNT_DIR" ]; do
|
while [ ! -d "$MOUNT_DIR" ]; do
|
||||||
echo "Waiting for directory to be created..."
|
echo "Waiting for directory to be created..."
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Wait until the directory is not empty
|
# Wait until the directory is not empty
|
||||||
while [ ! "$(ls -A "$MOUNT_DIR")" ]; do
|
while [ ! "$(ls -A "$MOUNT_DIR")" ]; do
|
||||||
echo "Waiting for directory to have content..."
|
echo "Waiting for directory to have content..."
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Space-separated list of absolute paths
|
# Space-separated list of absolute paths
|
||||||
BACKUP_DIR="$MOUNT_DIR/snapshots/latest"
|
BACKUP_DIR="$MOUNT_DIR/snapshots/latest"
|
||||||
|
|
||||||
# Iterate over each path in the array
|
# Iterate over each path in the array
|
||||||
while IFS= read -r ORIGINAL_PATH; do
|
while IFS= read -r ORIGINAL_PATH; do
|
||||||
# Skip empty paths
|
# Skip empty paths
|
||||||
[[ -z "$ORIGINAL_PATH" ]] && continue
|
[[ -z "$ORIGINAL_PATH" ]] && continue
|
||||||
|
|
||||||
# Construct the corresponding backup path
|
# Construct the corresponding backup path
|
||||||
BACKUP_PATH="$BACKUP_DIR$ORIGINAL_PATH"
|
BACKUP_PATH="$BACKUP_DIR$ORIGINAL_PATH"
|
||||||
|
|
||||||
# Check if the backup directory exists
|
# Check if the backup directory exists
|
||||||
if [[ ! -d "$BACKUP_PATH" ]]; then
|
if [[ ! -d "$BACKUP_PATH" ]]; then
|
||||||
echo "Backup directory not found: $BACKUP_PATH"
|
echo "Backup directory not found: $BACKUP_PATH"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure the original directory exists, create it if not
|
# Ensure the original directory exists, create it if not
|
||||||
if [[ ! -d "$ORIGINAL_PATH" ]]; then
|
if [[ ! -d "$ORIGINAL_PATH" ]]; then
|
||||||
echo "Creating original directory: $ORIGINAL_PATH"
|
echo "Creating original directory: $ORIGINAL_PATH"
|
||||||
mkdir -p "$ORIGINAL_PATH"
|
mkdir -p "$ORIGINAL_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use rsync to copy files, preserving permissions, ownership, and timestamps
|
# Use rsync to copy files, preserving permissions, ownership, and timestamps
|
||||||
rsync --archive --acls --xattrs --compress --verbose --human-readable --partial --progress "$BACKUP_PATH/" "$ORIGINAL_PATH/"
|
rsync --archive --acls --xattrs --compress --verbose --human-readable --partial --progress "$BACKUP_PATH/" "$ORIGINAL_PATH/"
|
||||||
done </backup-dirs
|
done </backup-dirs
|
||||||
|
|
||||||
kill -SIGINT $RESTIC_PID
|
kill -SIGINT $RESTIC_PID
|
||||||
umount /mnt/restic
|
umount /mnt/restic
|
||||||
|
|
||||||
echo "DONE"
|
echo "DONE"
|
||||||
) >"/var/log/backup-restore-$(date +%s).log"
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user