Skip to content

Instantly share code, notes, and snippets.

@basinilya
Created May 26, 2015 18:37
Show Gist options
  • Save basinilya/194ad2e1b9d9855a8508 to your computer and use it in GitHub Desktop.
Save basinilya/194ad2e1b9d9855a8508 to your computer and use it in GitHub Desktop.
OpenWrt collectd survive reboot
cat <<'EOFFILE' >/usr/local/bin/rrd-backup
#!/bin/sh
set -e
mkdir -p /usr/local/share/rrd
cd /tmp
chsum_prev=`tar -cf - rrd | md5sum`
while true; do
chsum=`tar -cf - rrd | tee rrd.tar | md5sum`
[ x"$chsum_prev" = x"$chsum" ] && break
chsum_prev=$chsum
done
cd /usr/local/share/rrd
tmpfile=`mktemp -p . rrd.tar.gz.XXXXXX`
gzip -c /tmp/rrd.tar >"$tmpfile"
mv "$tmpfile" rrd.tar.gz
rm -f /tmp/rrd.tar
EOFFILE
cat <<'EOFFILE' >/usr/local/bin/rrd-restore
#!/bin/sh
set -e
cd /tmp
if [ -d rrd ]; then
>&2 echo "directory 'rrd' exists"
exit 1
fi
tar -xzf /usr/local/share/rrd/rrd.tar.gz
EOFFILE
cat <<'EOFFILE' >/etc/init.d/rrd-restore
#!/bin/sh /etc/rc.common
START=70
start() {
/usr/local/bin/rrd-restore
}
EOFFILE
chmod 755 /usr/local/bin/rrd-backup /usr/local/bin/rrd-restore /etc/init.d/rrd-restore
/etc/init.d/rrd-restore enable
echo '10 5 * * * /usr/local/bin/rrd-backup # added by rrd-backup.txt' >>/etc/crontabs/root
/etc/init.d/cron restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment