{"id":217,"date":"2022-11-03T01:50:18","date_gmt":"2022-11-03T01:50:18","guid":{"rendered":"https:\/\/marshallpdavis.com\/?page_id=217"},"modified":"2022-11-04T01:18:42","modified_gmt":"2022-11-04T01:18:42","slug":"the-other-side","status":"publish","type":"page","link":"https:\/\/marshallpdavis.com\/?page_id=217","title":{"rendered":"The Other Side"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To finish off my move from cron to systemd timers,  I had one left which ran as my normal user on my home machine to download the prepared backup file, check it, then delete it from the server. All of this part was done as a normal user, no sudo, and nothing as root.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set up env, as per https:\/\/wiki.archlinux.org\/title\/Systemd\/User 2.1:<br>&#8220;The user instance of systemd does not inherit any of the environment variables set in places like .bashrc etc.&#8221;<code><br>env &gt; ~\/.config\/environment.d\/.conf<br>vi ~\/.config\/environment.d\/.conf<\/code><br>Clean up unneeded lines in the above config. If you aren&#8217;t sure, it is probably safe to leave it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create your service:<br><code>vi ~\/.config\/systemd\/user\/receivebackups.service<br>cat ~\/.config\/systemd\/user\/receivebackups.service<br>[Unit]<br>Description=Run receive WordPress backup script<br>[Service]<br>Type=oneshot<br>ExecStart=\/home\/marshall\/receivebackups.sh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check crontab to match times (my localtime is America\/New_York):<br><code>crontab -l<br>30 03 * * 0 \/home\/marshall\/receivebackups.sh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the timer unit:<br><code>vi ~\/.config\/systemd\/user\/receivebackups.timer<br>cat ~\/.config\/systemd\/user\/receivebackups.timer<br>[Unit]<br>Description=Run webbackups script weekly<br>[Timer]<br>OnCalendar=Sun *-*-* 08:30:00 UTC<br>Persistent=true<br>[Install]<br>WantedBy=timers.target<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable and start the timer:<br>systemctl &#8211;user enable receivebackups.timer<br>systemctl &#8211;user start receivebackups.timer<br>systemctl &#8211;user list-timers<br>NEXT LEFT LAST PASSED UNIT ACTIVATES<br>Sun 2022-11-06 03:30:00 EST 3 days left Mon 2022-10-31 21:13:11 EDT 2 days ago receivebackups.timer receivebackups.service<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, if you intend on the timer running without your user being logged in, follow https:\/\/wiki.archlinux.org\/title\/Systemd\/User 2.2:<br><code>loginctl enable-linger marshall<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And for completeness, I will include my sanitized script:<br><code>cat ~\/receivebackups.sh<br>#!\/bin\/bash<br>for x in ssh root@server ls \/backups\/; do<br>  scp root@server:\/backups\/$x \/storage\/webbackups<br>  tar ztvf \/storage\/webbackups\/$x &gt; \/dev\/null &amp;&amp;<br>  ssh root@server rm \/backups\/$x<br>done<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To finish off my move from cron to systemd timers, I had one left which ran as my normal user on my home machine to download the prepared backup file, check it, then delete it from the server. All of this part was done as a normal user, no sudo, and nothing as root. Set &hellip; <a href=\"https:\/\/marshallpdavis.com\/?page_id=217\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The Other Side<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":211,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-217","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217"}],"version-history":[{"count":6,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/217\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/217\/revisions\/225"}],"up":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/211"}],"wp:attachment":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}