~johanvandegriff/zfs-backup-pull

b9c4fad67a8729751fe7c94d31048b0736430fe6 — Johan Vandegriff 2 years ago 25b5bd0
initial files
A confuzer-backup-v2.sh => confuzer-backup-v2.sh +77 -0
@@ 0,0 1,77 @@
#!/bin/bash
echo 'Put "-n" to skip the snapshot'

if [[ "$1" != "-n" ]]; then
### START SNAPSHOT ###
snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_script="/home/loser/make-snapshot.sh"
port=2222
pool="lump"
remote_pool="brick"


echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of shots. Snapshots! date: `date`" | tee -a "$log"

datasets=`ssh -p "$port" "$remote" "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

ignore="apt-mirror
offline"

datasets_not_ignored=
for dataset in $datasets
do
  if echo "$ignore" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  #old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`
  datasets_not_ignored="$datasets_not_ignored $dataset"
done

echo "making snapshot of \"$datasets_not_ignored\" on \"$remote\" current time: `date`" | tee -a "$log"
ssh -o MACs=hmac-md5 -p "$port" "$remote" "$remote_script $datasets_not_ignored" | tee "$snapshot_file"
### END SNAPSHOT ###
fi





### START BACKUP ###
snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_script="/home/loser/send-incremental.sh"
port=2222
pool="lump"
remote_pool="brick"

echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of backups. Backups! date: `date`" | tee -a "$log"

new_snapshot=`cat "$snapshot_file"`
datasets=`ssh -p "$port" "$remote" "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

ignore="apt-mirror
offline"

for dataset in $datasets
do
  if echo "$ignore" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`

  until zfs list -t snapshot | grep "$dataset@$new_snapshot"
  do
    echo "receiving \"$dataset\" from \"$remote\", old: \"$old_snapshot\"" | tee -a "$log"
    ssh -o MACs=hmac-md5 -p "$port" "$remote" \
      "$remote_script $dataset $old_snapshot $new_snapshot" | \
      pv | zfs recv -Fdu "$pool"
  done
done
### END BACKUP ###

A confuzer-backup-v3.sh => confuzer-backup-v3.sh +63 -0
@@ 0,0 1,63 @@
#!/bin/bash
echo 'Put "-n" to skip the snapshot'

snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_snapshot_script="/home/loser/make-snapshot.sh"
remote_send_script="/home/loser/send-incremental.sh"
port=2222
pool="lump"
remote_pool="brick"
ignore_datasets="apt-mirror
offline
tmp"

echo "Getting list of datasets from the server..." | tee -a "$log"
datasets=`ssh -p "$port" "$remote" "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

echo "Removing ignored datasets from list..." | tee -a "$log"
datasets_not_ignored=
for dataset in $datasets
do
  if echo "$ignore_datasets" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  datasets_not_ignored="$datasets_not_ignored $dataset"
done

if [[ "$1" != "-n" ]]; then
### START SNAPSHOT ###
echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of shots. Snapshots! date: `date`" | tee -a "$log"

echo "making snapshot of \"$datasets_not_ignored\" on \"$remote\" current time: `date`" | tee -a "$log"
ssh -o MACs=hmac-md5 -p "$port" "$remote" "$remote_snapshot_script $datasets_not_ignored" | tee "$snapshot_file"
### END SNAPSHOT ###
fi






### START BACKUP ###
echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of backups. Backups! date: `date`" | tee -a "$log"

new_snapshot=`cat "$snapshot_file"`

for dataset in $datasets_not_ignored
do
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`

  until zfs list -t snapshot | grep "$dataset@$new_snapshot"
  do
    echo "receiving \"$dataset\" from \"$remote\", old: \"$old_snapshot\"" | tee -a "$log"
    ssh -o MACs=hmac-md5 -p "$port" "$remote" \
      "$remote_send_script $dataset $old_snapshot $new_snapshot" | \
      pv | zfs recv -Fdu "$pool"
  done
done
### END BACKUP ###

A confuzer-backup-v4.sh => confuzer-backup-v4.sh +72 -0
@@ 0,0 1,72 @@
#!/bin/bash
echo 'Put "-n" to skip the snapshot'

snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_snapshot_script="/home/loser/make-snapshot.sh"
remote_send_script="/home/loser/send-incremental.sh"
port=2230
local_pool="lump"
remote_pool="brick"
ignore_datasets="apt-mirror
offline
tmp"

echo "Getting list of datasets from the server..." | tee -a "$log"
datasets=`ssh -o MACs=hmac-md5 -p "$port" "$remote" \
  "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

echo "Removing ignored datasets from list..." | tee -a "$log"
datasets_not_ignored=
for dataset in $datasets
do
  if echo "$ignore_datasets" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  datasets_not_ignored="$datasets_not_ignored $dataset"
done

if [[ "$1" != "-n" ]]; then
### START SNAPSHOT ###
echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of shots. Snapshots! date: `date`" | tee -a "$log"

echo "making snapshot of \"$datasets_not_ignored\" on \"$remote\" current time: `date`" | tee -a "$log"
new_snapshot=`ssh -o MACs=hmac-md5 -p "$port" "$remote" "date +%Y-%m-%d_%H:%M:%S"`_backup
for dataset in datasets_not_ignored
do
  echo "snapshotting $dataset"
  ssh -o MACs=hmac-md5 -p "$port" "$remote" \
    "zfs snapshot ${remote_pool}/${dataset}@${new_snapshot}"
done

echo "$new_snapshot"  | tee "$snapshot_file"
### END SNAPSHOT ###
fi






### START BACKUP ###
echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of backups. Backups! date: `date`" | tee -a "$log"

new_snapshot=`cat "$snapshot_file"`

for dataset in $datasets_not_ignored
do
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${local_pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`

  until zfs list -t snapshot | grep "$dataset@$new_snapshot"
  do
    echo "receiving \"$dataset\" from \"$remote\", old: \"$old_snapshot\"" | tee -a "$log"
    ssh -o MACs=hmac-md5 -p "$port" "$remote" \
      "zfs send -R -I ${remote_pool}/${dataset}@${old_snapshot} ${remote_pool}/${dataset}@${new_snapshot}" | \
      pv | zfs recv -Fdu "$local_pool"
  done
done
### END BACKUP ###

A confuzer-backup.sh => confuzer-backup.sh +35 -0
@@ 0,0 1,35 @@
#!/bin/bash

snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_script="/home/loser/send-incremental.sh"
port=2222
pool="lump"
remote_pool="brick"

echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of backups. Backups! date: `date`" | tee -a "$log"

new_snapshot=`cat "$snapshot_file"`
datasets=`ssh -p "$port" "$remote" "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

ignore="apt-mirror
offline"

for dataset in $datasets
do
  if echo "$ignore" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`

  until zfs list -t snapshot | grep "$dataset@$new_snapshot"
  do
    echo "receiving \"$dataset\" from \"$remote\", old: \"$old_snapshot\"" | tee -a "$log"
    ssh -o MACs=hmac-md5 -p "$port" "$remote" \
      "$remote_script $dataset $old_snapshot $new_snapshot" | \
      pv | zfs recv -Fdu "$pool"
  done
done

A confuzer-snapshot.sh => confuzer-snapshot.sh +32 -0
@@ 0,0 1,32 @@
#!/bin/bash

snapshot_file="$HOME/snapshot.txt"
log="$HOME/backup.log"
remote="loser@confuzer.cloud"
remote_script="/home/loser/make-snapshot.sh"
port=2222
pool="lump"
remote_pool="brick"


echo "----------------------------------------------------" | tee -a "$log"
echo "Starting new round of shots. Snapshots! date: `date`" | tee -a "$log"

datasets=`ssh -p "$port" "$remote" "zfs list" | grep "${remote_pool}/" | cut -d' ' -f1 | cut -d/ -f2`

ignore="apt-mirror
offline"

datasets_not_ignored=
for dataset in $datasets
do
  if echo "$ignore" | grep "^${dataset}$" > /dev/null; then
    continue
  fi
  #https://stackoverflow.com/questions/41328041/shell-script-to-check-most-recent-zfs-snapshot#41329639
  #old_snapshot=`zfs list -t snapshot -o name,creation -s creation -r "${pool}/${dataset}" | tail -1 | cut -d ' ' -f 1 | cut -d '@' -f 2`
  datasets_not_ignored="$datasets_not_ignored $dataset"
done

echo "making snapshot of \"$datasets_not_ignored\" on \"$remote\" current time: `date`" | tee -a "$log"
ssh -o MACs=hmac-md5 -p "$port" "$remote" "$remote_script $datasets_not_ignored" | tee "$snapshot_file"