{"id":1050,"date":"2022-12-09T15:30:32","date_gmt":"2022-12-09T15:30:32","guid":{"rendered":"https:\/\/thomas.w-p.me.uk\/blog\/?p=1050"},"modified":"2022-12-09T16:32:12","modified_gmt":"2022-12-09T16:32:12","slug":"backing-up-openhabian","status":"publish","type":"post","link":"https:\/\/thomas.w-p.me.uk\/blog\/2022\/12\/backing-up-openhabian\/","title":{"rendered":"Backing up Openhabian"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I am using OpenHab more and more and not having a backup was starting to worry me. There are better solutions, but this works for me. I have a 1TB usb PCIe HDD which the OpenHabian is now running as the house nas, and this solution makes a backup each night and copies the newest file to the NAS with a full backup each Sunday.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It has to be run as root cron:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo crontab -e -u root<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then this is the cron for root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 2 * * * \/home\/openhabian\/bin\/backup-openhabian.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And this is the script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n##############################\n#  MUST be run by root cron!!\n##############################\nif &#91;&#91; $(date +%u) -gt 6 ]]; then\n    openhab-cli backup --full\nelse\n    openhab-cli backup\nfi\n\n# Copy to the nas\necho Copying the newset file to the NAS folder...\nfile=$( ls -t \/var\/lib\/openhab\/backups\/* | head -1 )\ncp $file \/mnt\/nas\/backup\/openhabian\/\n\n# delete files older than 7 days\necho Deleting anything older than 7 days...\nfind \/var\/lib\/openhab\/backups\/* -mtime +7 -exec rm {} \\;\necho Done!<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Restoring<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/community.openhab.org\/t\/solved-backup\/57666\">https:\/\/community.openhab.org\/t\/solved-backup\/57666<\/a> is for OH2, but I guess it will work the same. I really need to practise that with a blank SD card.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemclt stop openhab\nopenhab-cli restore \/var\/lib\/openhab\/backups\nsudo systemclt start openhab<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am using OpenHab more and more and not having a backup was starting to worry me. There are better solutions, but this works for me. I have a 1TB usb PCIe HDD which the OpenHabian is now running as the house nas, and this solution makes a backup each night and copies the newest &hellip; <a href=\"https:\/\/thomas.w-p.me.uk\/blog\/2022\/12\/backing-up-openhabian\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Backing up Openhabian<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[],"class_list":["post-1050","post","type-post","status-publish","format-standard","hentry","category-openhab"],"_links":{"self":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/comments?post=1050"}],"version-history":[{"count":5,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1050\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1050\/revisions\/1055"}],"wp:attachment":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/media?parent=1050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/categories?post=1050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/tags?post=1050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}