Skip to content

Commit

Permalink
Rewrite backup scripts for skylark
Browse files Browse the repository at this point in the history
  • Loading branch information
cradle8810 committed Jan 18, 2025
1 parent 34a481b commit d51c1e1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 130 deletions.
18 changes: 18 additions & 0 deletions inventories/host_vars/skylark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ backup_exclude:
home:
- "SparceImages/icloud_photo.sparsebundle/*"

backup_scripts:
dirs:
- name: "Nullpo"
src: "/skylark/Nullpo/"
dest: "/backup/Nullpo"
snapshotdir: "/backup/snapshots/Nullpo"
excludefilepath: "/home/hayato/backupscripts/Nullpo_exclude.txt"
- name: "NFS"
src: "/skylark/nfs/"
dest: "/backup/nfs"
snapshotdir: "/backup/snapshots/nfs"
excludefilepath: "/home/hayato/backupscripts/NFS_exclude.txt"
- name: "Home"
src: "/skylark/hayato/"
dest: "/backup/hayato"
snapshotdir: "/backup/snapshots/hayato"
excludefilepath: "/home/hayato/backupscripts/Home_exclude.txt"

services_start:
- nfs-server
- nmbd
Expand Down
13 changes: 6 additions & 7 deletions tasks/skylark/backupscripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
mode: '0755'

- name: Put Backup Script
ansible.builtin.copy:
src: "templates/skylark/{{ item }}"
dest: "{{ item }}"
ansible.builtin.template:
src: "templates/skylark/home/hayato/backupscripts/incrementalBackup.sh.j2"
dest: "/home/hayato/backupscripts/incremental{{ item.name }}Backup.sh"
owner: hayato
group: hayato
mode: '0755'
loop:
- /home/hayato/backupscripts/incrementalHomeBackup.sh
- /home/hayato/backupscripts/incrementalNullpoBackup.sh
- /home/hayato/backupscripts/incrementalNFSBackup.sh
loop: "{{ backup_scripts.dirs }}"
vars:
pathinfo: "{{ item }}"

- name: Put Exclude file
ansible.builtin.template:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

SRC='{{ pathinfo.src }}'
DEST='{{ pathinfo.dest }}'
SNAPSHOTSDIR='{{ pathinfo.snapshotdir }}'
EXCLUDEFILE='{{ pathinfo.excludefilepath }}'

TODAY=$(date +%Y%m%d_%H%M%S)

# rsync
echo "rsync -av8 --delete --exclude-from=${EXCLUDEFILE} ${SRC} ${DEST}"
rsync -av8 --delete --exclude-from="${EXCLUDEFILE}" ${SRC} ${DEST}
RETVAL=$?

# Snapshot 作成
sudo btrfs subvolume snapshot -r "${DEST}" "${SNAPSHOTSDIR}/${TODAY}"

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit d51c1e1

Please sign in to comment.