HashBackup setup: Difference between revisions

From Notes to self
Jump to navigation Jump to search
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:
* <code># pkg install linux_base-rl9</code>
* <code># pkg install linux_base-rl9</code>
* Download <code>hb</code> from https://www.hashbackup.com/hashbackup/download.html to <code>/root/bin/hb</code>
* Download <code>hb</code> from https://www.hashbackup.com/hashbackup/download.html to <code>/root/bin/hb</code>
* # hb init -c /hashbackup
* <code># chown root:wheel /root/bin/hb</code>
* <code># chmod 700 /root/bin/hb</code>
* <code># hb init -c /hashbackup</code>
* Create <code>/compat/linux/hashbackup/dest.conf</code>
* Create <code>/compat/linux/hashbackup/dest.conf</code>
<pre>
<pre>
Line 15: Line 17:
secure
secure
</pre>
</pre>
:* <code># chmod 400 /var/hashbackup/dest.conf</code>
:* <code># chmod 400 /compat/linux/hashbackup/dest.conf</code>
* Customize <code>/compat/linux/hashbackup/inex.conf</code>
* Customize <code>/compat/linux/hashbackup/inex.conf</code>
<pre>
<pre>
Line 29: Line 31:
ex /hb/root/.cache
ex /hb/root/.cache
ex /hb/root/.gvfs
ex /hb/root/.gvfs
ex /hb/root/npbin/.hb-daily-marker
...
...
ex /usr/local/mysqlbackups/backup
ex /usr/local/mysqlbackups/mysqldump.password
</pre>
</pre>
* Set configuration options:
* Set configuration options:
Line 44: Line 49:
<pre>
<pre>
m h * * * /usr/bin/touch /root/npbin/.hb-daily-marker
m h * * * /usr/bin/touch /root/npbin/.hb-daily-marker
</pre>
* <code>/usr/local/etc/profile</code>
<pre>
export HASHBACKUP_DIR=/hashbackup
</pre>
* <code>/root/npbin/hb.sh</code>, to be added to cron
<pre>
#!/bin/sh
set -e
if zfs list -H -t snapshot -o name | grep -q "@hashbackup"; then
  printf "%s\n" "The snapshots @hashbackup exist:"
  zfs list -H -t snapshot -o name | grep "@hashbackup"
  exit 1
fi
export HASHBACKUP_DIR=/hashbackup
hb="/root/bin/hb"
marker=/root/npbin/.hb-daily-marker
zfs snapshot zroot/ROOT/default@hashbackup
zfs snapshot -r zroot/home@hashbackup
if [ -f $marker ]; then
  n=$($hb upgrade 2>&1 >/dev/null)
  if [ -n "$n" ]; then
    echo "$n" | /usr/bin/mail -s "$(echo "$n" | tail -n 1)" root
    chown root:wheel "$hb"
    chmod 700 "$hb"
  fi
fi
DIRS="/boot /etc /root /usr/local/etc /usr/local/www /var/cron"
DIRSh="/home /home/alik"
DIRShop="/home/alik /home"
for d in ${DIRS}; do
  mkdir -p /compat/linux/hb"${d}"
  mount_nullfs -o ro /.zfs/snapshot/hashbackup"${d}" /compat/linux/hb"${d}"
done
mkdir -p /compat/linux/hb/home
for d in ${DIRSh}; do
  mount_nullfs -o ro "${d}"/.zfs/snapshot/hashbackup /compat/linux/hb"${d}"
done
err=0
if [ -f /compat/linux/hb/etc/rc.conf ] \
  && [ -d /compat/linux/hb/home/alik/.config ]; then
  $hb backup -X /hb/boot/loader.conf /hb || err=1
  $hb retain -t 10d -s safe -x 3m || err=1
  $hb retain -x 2d /usr/local/mysqlbackups || err=1
else
  printf "%s\n" "/compat/linux/hb is not ready"
  err=1
fi
if [ -f $marker ]; then
  $hb tune
  $hb selftest
  $hb dest verify
  rm $marker
fi
for d in ${DIRS} ${DIRShop}; do
  umount -f -t nullfs /compat/linux/hb"${d}"
done
zfs destroy zroot/ROOT/default@hashbackup
zfs destroy -r zroot/home@hashbackup
exit "$err"
</pre>
* Crontab:
<pre>
15,45 * * * * /usr/local/bin/chronic /usr/sbin/idprio 31 /usr/bin/nice -n 20 /root/npbin/hb.sh
</pre>
</pre>


[[Category: FreeBSD]]
[[Category: FreeBSD]]

Latest revision as of 17:43, 11 April 2025

destname fbsd
type s3
host example.com
location loc
accesskey ...
secretkey ...
bucket fbsd
class ia
secure
  • # chmod 400 /compat/linux/hashbackup/dest.conf
  • Customize /compat/linux/hashbackup/inex.conf
ex /hb/boot/

ex /hb/home/*/.sh_history
ex /hb/home/*/.bash_history
ex /hb/home/*/.cache
ex /hb/home/*/.gvfs

ex /hb/root/.sh_history
ex /hb/root/.bash_history
ex /hb/root/.cache
ex /hb/root/.gvfs
ex /hb/root/npbin/.hb-daily-marker
...
ex /usr/local/mysqlbackups/backup
ex /usr/local/mysqlbackups/mysqldump.password
  • Set configuration options:
hb config cache-size-limit ...
hb config dedup-mem ...GB
hb config copy-executable True
hb config no-backup-tag .nobackup,CACHEDIR.TAG
hb config pack-age-days 0
hb config pack-download-limit 10TB
hb config pack-percent-free 10
  • Crontab:
m h * * * /usr/bin/touch /root/npbin/.hb-daily-marker
  • /usr/local/etc/profile
export HASHBACKUP_DIR=/hashbackup
  • /root/npbin/hb.sh, to be added to cron
#!/bin/sh

set -e

if zfs list -H -t snapshot -o name | grep -q "@hashbackup"; then
  printf "%s\n" "The snapshots @hashbackup exist:"
  zfs list -H -t snapshot -o name | grep "@hashbackup"
  exit 1
fi

export HASHBACKUP_DIR=/hashbackup

hb="/root/bin/hb"
marker=/root/npbin/.hb-daily-marker

zfs snapshot zroot/ROOT/default@hashbackup
zfs snapshot -r zroot/home@hashbackup

if [ -f $marker ]; then
  n=$($hb upgrade 2>&1 >/dev/null)
  if [ -n "$n" ]; then
    echo "$n" | /usr/bin/mail -s "$(echo "$n" | tail -n 1)" root
    chown root:wheel "$hb"
    chmod 700 "$hb"
  fi
fi

DIRS="/boot /etc /root /usr/local/etc /usr/local/www /var/cron"
DIRSh="/home /home/alik"
DIRShop="/home/alik /home"

for d in ${DIRS}; do
  mkdir -p /compat/linux/hb"${d}"
  mount_nullfs -o ro /.zfs/snapshot/hashbackup"${d}" /compat/linux/hb"${d}"
done
mkdir -p /compat/linux/hb/home
for d in ${DIRSh}; do
  mount_nullfs -o ro "${d}"/.zfs/snapshot/hashbackup /compat/linux/hb"${d}"
done

err=0

if [ -f /compat/linux/hb/etc/rc.conf ] \
  && [ -d /compat/linux/hb/home/alik/.config ]; then
  $hb backup -X /hb/boot/loader.conf /hb || err=1
  $hb retain -t 10d -s safe -x 3m || err=1
  $hb retain -x 2d /usr/local/mysqlbackups || err=1
else
  printf "%s\n" "/compat/linux/hb is not ready"
  err=1
fi

if [ -f $marker ]; then
  $hb tune
  $hb selftest
  $hb dest verify
  rm $marker
fi

for d in ${DIRS} ${DIRShop}; do
  umount -f -t nullfs /compat/linux/hb"${d}"
done

zfs destroy zroot/ROOT/default@hashbackup
zfs destroy -r zroot/home@hashbackup

exit "$err"
  • Crontab:
15,45 * * * * /usr/local/bin/chronic /usr/sbin/idprio 31 /usr/bin/nice -n 20 /root/npbin/hb.sh