Skip to content

Instantly share code, notes, and snippets.

@dimaskiddo
Last active January 11, 2024 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimaskiddo/20766d70bf77d610852d2581f19fa01d to your computer and use it in GitHub Desktop.
Save dimaskiddo/20766d70bf77d610852d2581f19fa01d to your computer and use it in GitHub Desktop.
Debian Linux Sanoid - Syncoid Packages Setup Script
#!/usr/bin/env bash
apt-get -y update --allow-releaseinfo-change
apt-get -y install ca-certificates apt-transport-https software-properties-common lsb-release bash-completion dirmngr gnupg curl wget rsync logrotate byobu
apt-get -y install procps pv lzop mbuffer libcapture-tiny-perl libconfig-inifiles-perl
mkdir -p /usr/bin
mkdir -p /usr/local/bin
mkdir -p /etc/sanoid
wget -O /usr/bin/run-one https://raw.githubusercontent.com/dustinkirkland/run-one/master/run-one
chmod 755 /usr/bin/run-one
ln -sf /usr/bin/run-one /usr/bin/run-this-one
ln -sf /usr/bin/run-one /usr/bin/run-one-constantly
ln -sf /usr/bin/run-one /usr/bin/run-one-until-success
ln -sf /usr/bin/run-one /usr/bin/run-one-until-failure
ln -sf /usr/bin/run-one /usr/bin/keep-one-running
wget -O /usr/local/bin/sanoid https://raw.githubusercontent.com/jimsalterjrs/sanoid/master/sanoid
chmod 755 /usr/local/bin/sanoid
wget -O /usr/local/bin/syncoid https://raw.githubusercontent.com/jimsalterjrs/sanoid/master/syncoid
chmod 755 /usr/local/bin/syncoid
wget -O /etc/sanoid/sanoid.defaults.conf https://raw.githubusercontent.com/jimsalterjrs/sanoid/master/sanoid.defaults.conf
chmod 644 /etc/sanoid/sanoid.defaults.conf
cat << EOF > /usr/local/bin/sanoid-cron
#!/usr/bin/env bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
(
echo "--------------------------------------------------"
echo \$(date) sanoid start
echo ""
run-one sanoid --cron --verbose
echo ""
echo \$(date) sanoid end
echo "--------------------------------------------------"
) >> /var/log/sanoid-cron.log 2>&1 &
exit 0
EOF
chmod 755 /usr/local/bin/sanoid-cron
cat << EOF > /usr/local/bin/syncoid-cron
#!/usr/bin/env bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
(
echo "--------------------------------------------------"
echo \$(date) syncoid start
echo ""
echo "Backing-up {{ SYNCOID_SOURCE_DATASET }} from {{ SYNCOID_SOURCE_IP }}"
syncoid -r {{ SYNCOID_SOURCE_USER }}@{{ SYNCOID_SOURCE_IP }}:{{ SYNCOID_SOURCE_DATASET }} {{ SYNCOID_SOURCE_DATASET }}/{{ SYNCOID_SOURCE_IP }}
echo ""
echo \$(date) syncoid end
echo "--------------------------------------------------"
) >> /var/log/syncoid-cron.log 2>&1 &
exit 0
EOF
chmod 755 /usr/local/bin/syncoid-cron
cat << EOF > /etc/sanoid/sanoid.conf
## ZFS Section ##
[{{ ZFS_DATASET_NAME }}]
use_template = default
process_children_only = yes
recursive = yes
## Template Section ##
[template_default]
hourly = 0
daily = 14
monthly = 3
yearly = 0
autosnap = yes
autoprune = yes
EOF
chmod 644 /etc/sanoid/sanoid.conf
cat << EOF > /etc/logrotate.d/sanoid-cron
/var/log/sanoid-cron.log {
create 0644 root root
rotate 14
daily
compress
missingok
notifempty
}
EOF
chmod 644 /etc/logrotate.d/sanoid-cron
cat << EOF > /etc/logrotate.d/syncoid-cron
/var/log/syncoid-cron.log {
create 0644 root root
rotate 14
daily
compress
missingok
notifempty
}
EOF
chmod 644 /etc/logrotate.d/syncoid-cron
touch /var/log/sanoid-cron.log
touch /var/log/syncoid-cron.log
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment