btrfs maintenance scripts
parent
252ec87fe3
commit
016dd83a52
|
@ -111,7 +111,6 @@
|
|||
hosts:
|
||||
- pikvm
|
||||
become: true
|
||||
hosts: pikvm
|
||||
vars:
|
||||
domain: monotremata.xyz
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
BTRFS_ROOT="${BTRFS_ROOT:-/mnt/btr_pool}"
|
||||
|
||||
btrfs -v balance start --background "$BTRFS_ROOT"
|
||||
|
||||
# shellcheck disable=SC2064
|
||||
trap "btrfs balance cancel $BTRFS_ROOT" INT
|
||||
|
||||
printf '=================\n'
|
||||
while ! btrfs -v balance status "$BTRFS_ROOT"; do
|
||||
printf '________________\n'
|
||||
sleep 60
|
||||
done
|
||||
printf '=================\n'
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
defragment() {
|
||||
btrfs filesystem defragment -v -r -czstd "$@"
|
||||
}
|
||||
|
||||
list_subvols() {
|
||||
btrfs subvolume list "$@" | awk '{ print $9 }'
|
||||
}
|
||||
|
||||
is_readonly() {
|
||||
btrfs subvolume show "$@" | grep -q "readonly"
|
||||
}
|
||||
|
||||
BTRFS_ROOT="${BTRFS_ROOT:-/mnt/btr_pool}"
|
||||
|
||||
for subvol in $(list_subvols "$BTRFS_ROOT"); do
|
||||
subvol_path="$BTRFS_ROOT"/"$subvol"
|
||||
is_readonly "$subvol_path" || defragment "$subvol_path"
|
||||
done
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
scrub_status() {
|
||||
btrfs scrub status "$@" |
|
||||
tee /dev/stderr |
|
||||
grep "^Status:" |
|
||||
awk '{ print $2}'
|
||||
}
|
||||
|
||||
BTRFS_ROOT="${BTRFS_ROOT:-/mnt/btr_pool}"
|
||||
|
||||
btrfs scrub start "$BTRFS_ROOT"
|
||||
sleep 10
|
||||
|
||||
# shellcheck disable=SC2064
|
||||
trap "btrfs scrub cancel $BTRFS_ROOT" INT
|
||||
|
||||
printf '=================\n'
|
||||
while [ "$(scrub_status "${BTRFS_ROOT}")" = "running" ]; do
|
||||
printf '________________\n'
|
||||
sleep 60
|
||||
done
|
||||
printf '=================\n'
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
FS_ROOT="${BTRFS_ROOT:-/mnt/btr_pool}"
|
||||
fstrim -v "$FS_ROOT"
|
|
@ -2,6 +2,7 @@
|
|||
- name: install packages
|
||||
apk:
|
||||
name:
|
||||
- btrbk
|
||||
- btrfs-progs
|
||||
- cryptsetup
|
||||
- gnupg
|
||||
|
|
|
@ -2,3 +2,14 @@
|
|||
- name: alpine setup
|
||||
include_tasks: alpine.yml
|
||||
when: ansible_distribution == "Alpine"
|
||||
|
||||
- name: copy maintainance scripts
|
||||
copy:
|
||||
src: "bin/{{ item }}"
|
||||
dest: "/usr/local/bin/{{ item }}"
|
||||
mode: "755"
|
||||
loop:
|
||||
- "btr_defrag.sh"
|
||||
- "btr_balance.sh"
|
||||
- "btr_scrub.sh"
|
||||
- "fs_trim.sh"
|
||||
|
|
Loading…
Reference in New Issue