{"id":563,"date":"2026-11-05T13:52:36","date_gmt":"2026-11-05T05:52:36","guid":{"rendered":"https:\/\/blog.jianguoyun.com\/en\/?p=563"},"modified":"2026-11-05T13:52:36","modified_gmt":"2026-11-05T05:52:36","slug":"how-to-automate-cron-backup-on-linux-and-sync-to-cloud","status":"publish","type":"post","link":"https:\/\/blog.jianguoyun.com\/en\/?p=563","title":{"rendered":"How to Automate Cron Backup on Linux and Sync to Cloud"},"content":{"rendered":"<p><strong>Cron schedules the backup. Nutstore gets the result onto your other devices. These are two separate jobs \u2014 and mixing them up is how people lose data.<\/strong><\/p>\n<p>Nutstore does not run your cron jobs or execute scripts. Sync is not an independent backup \u2014 it can propagate changes and deletions. Edits that are never saved or never uploaded will not appear in the cloud. Feature availability may vary by platform and plan, and Nutstore is <strong>not recommended for code sync<\/strong>.<\/p>\n<p>This guide covers machines with a graphical desktop environment \u2014 Linux, Windows, or macOS. The Nutstore half is set up through the desktop client and a file manager&rsquo;s right-click menu, so headless servers are outside what it demonstrates.<\/p>\n<hr>\n<h2 id=\"what-youll-need-before-you-start\">What You&rsquo;ll Need Before You Start<\/h2>\n<p><strong>On the Linux machine (or any supported desktop OS):<\/strong><\/p>\n<ul>\n<li>A Linux desktop distribution with a graphical environment and <code>cron<\/code> \/ <code>crontab<\/code> available (pre-installed on most distros; verify with <code>crontab -l<\/code> and <code>systemctl status cron<\/code> or <code>systemctl status crond<\/code>).<\/li>\n<li>A shell account with permission to edit its own crontab \u2014 no root needed for user-level jobs.<\/li>\n<li>Enough free disk space for at least 2\u20133 rotations of your backup set.<\/li>\n<li>Basic familiarity with a terminal and a text editor (<code>nano<\/code>, <code>vim<\/code>, etc.).<\/li>\n<\/ul>\n<p><strong>For the sync half:<\/strong><\/p>\n<ul>\n<li>A Nutstore account.<\/li>\n<li>The Nutstore desktop client installed on the machine that holds the backup folder, on a desktop session where you can complete the client&rsquo;s setup. Nutstore ships desktop clients for <strong>Windows, macOS, and Linux<\/strong> \u2014 one of the few domestic providers with <strong>full-platform support<\/strong> \u2014 so the machine writing the backups and the machine reading them don&rsquo;t need to run the same OS.<\/li>\n<li>At least one other supported device or browser access to verify the files arrived.<\/li>\n<\/ul>\n<p><strong>What you do <em>not<\/em> need:<\/strong><\/p>\n<ul>\n<li>No <code>mklink<\/code>, no symlinks, no relocating files into a designated sync directory. <strong>Arbitrary Folder Sync<\/strong> lets you right-click an existing folder \u2014 including the one your script writes to \u2014 and sync it in place.<\/li>\n<li>No Nutstore-side scheduling configuration. There isn&rsquo;t any.<\/li>\n<\/ul>\n<blockquote>\n<p><strong>Platform\/plan caveat:<\/strong> Specific features differ by platform and plan. Confirm what your plan includes before building a workflow around it.<\/p>\n<\/blockquote>\n<hr>\n<h2 id=\"step-by-step-configuration-guide\">Step-by-Step Configuration Guide<\/h2>\n<h3 id=\"step-1-decide-what-a-backup-means-for-your-case\">Step 1 \u2014 Decide what a &ldquo;backup&rdquo; means for your case<\/h3>\n<p>Three things get conflated in this topic. Separate them first.<\/p>\n<table>\n<thead>\n<tr>\n<th>Term<\/th>\n<th>What it actually does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Scheduled local backup<\/strong><\/td>\n<td>Cron runs a script that writes a copy of your files at the moment it runs. What that copy represents depends on how the script is written; a copy produced by ordinary file tools is not automatically a consistent point-in-time image of your filesystem.<\/td>\n<\/tr>\n<tr>\n<td><strong>Sync<\/strong><\/td>\n<td>A client mirrors a folder&rsquo;s <em>current state<\/em> to the cloud and to other devices. If a file is deleted locally, that deletion can propagate.<\/td>\n<\/tr>\n<tr>\n<td><strong>Independent backup<\/strong><\/td>\n<td>A separate copy that does not track the live folder&rsquo;s changes.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The two script options below produce <strong>different kinds of local output<\/strong>: Option A copies the source into the destination on each run, while Option B accumulates dated archives. Pick the one that matches what you actually want to be able to recover. This guide gives you job #1 (cron) and a delivery mechanism for the output, but <strong>sync does not replace an independent backup<\/strong>.<\/p>\n<h3 id=\"step-2-create-the-destination-and-script-folders\">Step 2 \u2014 Create the destination and script folders<\/h3>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code>mkdir<span style=\"color: #BBB\"> <\/span>-p<span style=\"color: #BBB\"> <\/span>~\/backups\/daily\nmkdir<span style=\"color: #BBB\"> <\/span>-p<span style=\"color: #BBB\"> <\/span>~\/scripts\n<\/code><\/pre>\n<\/div>\n<p>Put the destination somewhere stable that won&rsquo;t be moved or renamed later, and keep your scripts in a dedicated directory so the paths used in the crontab entry actually exist. Note the real-world trap: <strong>share links break if the source file or folder is moved or renamed<\/strong>, so pick a final path now rather than reorganizing later.<\/p>\n<h3 id=\"step-3-create-a-cron-backup-script-on-linux\">Step 3 \u2014 Create a cron backup script on Linux<\/h3>\n<p>A working cron backup script on Linux has two parts: the tools it calls must be findable, and its source checks must fail safely. Handle both before writing any backup logic.<\/p>\n<p><strong>First, locate the external commands the script will call.<\/strong> Cron runs with a minimal environment, so run this in your normal shell:<\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code><span style=\"color: #008000\">command<\/span><span style=\"color: #BBB\"> <\/span>-v<span style=\"color: #BBB\"> <\/span>rsync<span style=\"color: #BBB\"> <\/span>tar<span style=\"color: #BBB\"> <\/span>date<span style=\"color: #BBB\"> <\/span>mkdir<span style=\"color: #BBB\"> <\/span>find<span style=\"color: #BBB\"> <\/span>wc<span style=\"color: #BBB\"> <\/span>dirname<span style=\"color: #BBB\"> <\/span>basename\n<\/code><\/pre>\n<\/div>\n<p>Each line of output is that program&rsquo;s absolute path \u2014 for example <code>\/usr\/bin\/rsync<\/code>, <code>\/usr\/bin\/tar<\/code>, <code>\/bin\/mkdir<\/code>, <code>\/usr\/bin\/find<\/code>, <code>\/usr\/bin\/wc<\/code>. On most distributions these sit in <code>\/usr\/bin<\/code> and <code>\/bin<\/code>. If any command lives elsewhere, note the directory, because you will put it on the script&rsquo;s <code>PATH<\/code>. <strong><code>wc<\/code> matters in particular<\/strong>, because the exact-mirror guidance below uses it.<\/p>\n<p>The scripts set their own <code>PATH<\/code> rather than relying on whatever cron hands them. The alternative \u2014 calling every tool by absolute path \u2014 works too, but makes the scripts harder to read.<\/p>\n<p>Create the script file at the path Step 2 prepared:<\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code>nano<span style=\"color: #BBB\"> <\/span>~\/scripts\/backup.sh\n<\/code><\/pre>\n<\/div>\n<p><strong>Option A \u2014 one-way, non-deleting copy with <code>rsync<\/code> (fast, space-efficient; copies the source into the destination without deleting destination-only files):<\/strong><\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code><span style=\"color: #3D7B7B; font-style: italic\">#!\/bin\/bash<\/span>\n<span style=\"color: #3D7B7B; font-style: italic\"># ~\/scripts\/backup.sh<\/span>\n<span style=\"color: #008000\">set<\/span><span style=\"color: #BBB\"> <\/span>-euo<span style=\"color: #BBB\"> <\/span>pipefail\n\n<span style=\"color: #3D7B7B; font-style: italic\"># cron runs with a minimal environment; set a PATH containing the tools called below.<\/span>\n<span style=\"color: #008000\">export<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #19177C\">PATH<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin&quot;<\/span>\n\n<span style=\"color: #19177C\">SRC<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$HOME<\/span><span style=\"color: #BA2121\">\/documents&quot;<\/span><span style=\"color: #BBB\">          <\/span><span style=\"color: #3D7B7B; font-style: italic\"># what you want backed up<\/span>\n<span style=\"color: #19177C\">DEST<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$HOME<\/span><span style=\"color: #BA2121\">\/backups\/daily&quot;<\/span><span style=\"color: #BBB\">     <\/span><span style=\"color: #3D7B7B; font-style: italic\"># what Nutstore will sync<\/span>\n\n<span style=\"color: #3D7B7B; font-style: italic\"># Source checks. Each one fails safely and says why.<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>-d<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> does not exist; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>-r<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">||<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>ls<span style=\"color: #BBB\"> <\/span>-A<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;\/dev\/null<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> is not readable; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>-z<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">$(<\/span>ls<span style=\"color: #BBB\"> <\/span>-A<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">)<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> is empty; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n\nmkdir<span style=\"color: #BBB\"> <\/span>-p<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$DEST<\/span><span style=\"color: #BA2121\">&quot;<\/span>\nrsync<span style=\"color: #BBB\"> <\/span>-a<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">\/&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$DEST<\/span><span style=\"color: #BA2121\">\/&quot;<\/span>\n<\/code><\/pre>\n<\/div>\n<p><strong>Why the readability check comes before the emptiness check.<\/strong> A plain <code>ls -A<\/code> test alone cannot tell &ldquo;empty&rdquo; apart from &ldquo;unreadable&rdquo;: if the directory cannot be listed, the command fails, and the naive test treats that failure as emptiness or prints a misleading reason. Testing <code>-r<\/code> and the exit status of <code>ls<\/code> first makes the script abort with the correct message on an unreadable source, so the emptiness check only ever runs on a directory the script can actually read.<\/p>\n<p><strong>Why there is no <code>--delete<\/code> here.<\/strong> Notice the <code>rsync<\/code> line copies files into <code>DEST<\/code> but never removes anything from it. That is deliberate, and it is the recommended default. Adding <code>--delete<\/code> makes the destination match the source <em>exactly<\/em> \u2014 which also means it deletes anything in the destination that isn&rsquo;t in the source. <strong>Leave it off unless you have a specific reason to mirror exactly and you understand the risk<\/strong>, which is covered below.<\/p>\n<p><strong>What you give up by omitting <code>--delete<\/code>:<\/strong> if you delete a file from <code>SRC<\/code>, the copy in <code>DEST<\/code> stays behind, so the destination grows stale rather than tracking the source precisely. For a backup folder that is usually the safer trade \u2014 a stale extra file costs disk space, while a wrongly deleted file costs data.<\/p>\n<p><strong>Option B \u2014 timestamped archive (keeps a dated copy per run, larger, better rotation story):<\/strong><\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code><span style=\"color: #3D7B7B; font-style: italic\">#!\/bin\/bash<\/span>\n<span style=\"color: #3D7B7B; font-style: italic\"># ~\/scripts\/backup.sh<\/span>\n<span style=\"color: #008000\">set<\/span><span style=\"color: #BBB\"> <\/span>-euo<span style=\"color: #BBB\"> <\/span>pipefail\n\n<span style=\"color: #3D7B7B; font-style: italic\"># cron runs with a minimal environment; set a PATH containing the tools called below.<\/span>\n<span style=\"color: #008000\">export<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #19177C\">PATH<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin&quot;<\/span>\n\n<span style=\"color: #19177C\">SRC<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$HOME<\/span><span style=\"color: #BA2121\">\/documents&quot;<\/span>\n<span style=\"color: #19177C\">DEST<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$HOME<\/span><span style=\"color: #BA2121\">\/backups\/daily&quot;<\/span>\n<span style=\"color: #19177C\">STAMP<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #008000; font-weight: bold\">$(<\/span>date<span style=\"color: #BBB\"> <\/span>+%Y-%m-%d_%H%M%S<span style=\"color: #008000; font-weight: bold\">)<\/span>\n<span style=\"color: #19177C\">RETAIN_DAYS<\/span><span style=\"color: #666\">=14<\/span>\n<span style=\"color: #19177C\">RETAIN_MIN<\/span><span style=\"color: #666\">=<\/span><span style=\"color: #008000; font-weight: bold\">$((<\/span><span style=\"color: #19177C\">RETAIN_DAYS<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">*<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1440<\/span><span style=\"color: #008000; font-weight: bold\">))<\/span><span style=\"color: #BBB\">   <\/span><span style=\"color: #3D7B7B; font-style: italic\"># retention window expressed in minutes<\/span>\n\n<span style=\"color: #3D7B7B; font-style: italic\"># Same source checks as Option A, for the same reasons.<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>-d<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> does not exist; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>-r<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">||<\/span><span style=\"color: #BBB\"> <\/span>!<span style=\"color: #BBB\"> <\/span>ls<span style=\"color: #BBB\"> <\/span>-A<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;\/dev\/null<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> is not readable; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">[<\/span><span style=\"color: #BBB\"> <\/span>-z<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">$(<\/span>ls<span style=\"color: #BBB\"> <\/span>-A<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">)<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">]<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Source directory <\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\"> is empty; aborting.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n\nmkdir<span style=\"color: #BBB\"> <\/span>-p<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$DEST<\/span><span style=\"color: #BA2121\">&quot;<\/span>\n\n<span style=\"color: #3D7B7B; font-style: italic\"># Rotate only after a successful archive, so a failed backup never deletes history.<\/span>\n<span style=\"color: #3D7B7B; font-style: italic\"># Only this script&#39;s own archives (documents_*.tar.gz) are eligible for removal.<\/span>\n<span style=\"color: #008000; font-weight: bold\">if<\/span><span style=\"color: #BBB\"> <\/span>tar<span style=\"color: #BBB\"> <\/span>-czf<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$DEST<\/span><span style=\"color: #BA2121\">\/documents_<\/span><span style=\"color: #19177C\">$STAMP<\/span><span style=\"color: #BA2121\">.tar.gz&quot;<\/span><span style=\"color: #BBB\"> <\/span>-C<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">$(<\/span>dirname<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">)<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">$(<\/span>basename<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$SRC<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #008000; font-weight: bold\">)<\/span><span style=\"color: #BA2121\">&quot;<\/span>;<span style=\"color: #BBB\"> <\/span><span style=\"color: #008000; font-weight: bold\">then<\/span>\n<span style=\"color: #BBB\">  <\/span>find<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$DEST<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span>-name<span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&#39;documents_*.tar.gz&#39;<\/span><span style=\"color: #BBB\"> <\/span>-mmin<span style=\"color: #BBB\"> <\/span>+<span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #19177C\">$RETAIN_MIN<\/span><span style=\"color: #BA2121\">&quot;<\/span><span style=\"color: #BBB\"> <\/span>-delete\n<span style=\"color: #008000; font-weight: bold\">else<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">echo<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #BA2121\">&quot;Archive creation failed; skipping rotation.&quot;<\/span><span style=\"color: #BBB\"> <\/span>&gt;&amp;<span style=\"color: #666\">2<\/span>\n<span style=\"color: #BBB\">  <\/span><span style=\"color: #008000\">exit<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>\n<span style=\"color: #008000; font-weight: bold\">fi<\/span>\n<\/code><\/pre>\n<\/div>\n<p><strong>Where the cleanup line goes, and why.<\/strong> The <code>find<\/code> line sits <strong>inside<\/strong> the <code>if<\/code>, immediately after a successful <code>tar<\/code>. It never runs unless the archive was created. Two details in that line are deliberate and worth understanding before you change them:<\/p>\n<ul>\n<li><strong>The pattern is <code>-name 'documents_*.tar.gz'<\/code>, not <code>-name '*.tar.gz'<\/code>.<\/strong> Only archives this script itself created \u2014 the ones matching the <code>documents_&lt;timestamp&gt;.tar.gz<\/code> naming scheme from the <code>tar<\/code> line \u2014 are eligible for removal. If you keep unrelated compressed backups in the same folder, they are left untouched; a bare <code>*.tar.gz<\/code> pattern would instead delete those too once they aged past the cutoff, which is rarely what you want.<\/li>\n<li><strong>The age test is <code>-mmin +\"$RETAIN_MIN\"<\/code>, where <code>RETAIN_MIN=$((RETAIN_DAYS * 1440))<\/code>.<\/strong> With <code>RETAIN_DAYS=14<\/code>, that evaluates to <code>-mmin +20160<\/code>, meaning &ldquo;older than about 20160 minutes, that is, roughly 14 days.&rdquo; Treat that as approximate, not exact: GNU <code>find<\/code> truncates each file&rsquo;s age to whole minutes before applying <code>+N<\/code>, so <code>+20160<\/code> selects files at least 20161 minutes old \u2014 up to a minute more than the nominal 14 days. The cutoff therefore lands a fraction past the 14-day mark rather than exactly on it. If you genuinely need an exact age boundary, compare file timestamps directly (for example with <code>find ... -newermt<\/code> against a computed reference date) instead of relying on <code>-mmin<\/code> rounding. Do not swap in <code>-mtime +14<\/code> expecting the same behavior either: GNU <code>find<\/code>&rsquo;s <code>-mtime<\/code> rounds each file&rsquo;s age down to whole 24-hour periods before comparing, so <code>-mtime +14<\/code> actually selects files at least 15 full days old, not files older than 14 days. If you prefer <code>-mtime<\/code> for readability, remember the window is effectively one day wider than the number suggests.<\/li>\n<\/ul>\n<p>Archives that match the pattern and pass the age test are permanently removed on that run, so the folder keeps approximately 14 days of dated history and stops growing without bound. Change <code>RETAIN_DAYS<\/code> to widen or narrow that window, and note that <code>-delete<\/code> is permanent.<\/p>\n<p><strong>Why the <code>if<\/code> wrapper instead of a plain sequential line.<\/strong> Rotation should depend on backup success. Writing that dependency explicitly means a failed archive can never trigger the cleanup, regardless of what happens elsewhere in the script \u2014 if you later add <code>|| true<\/code> to the <code>tar<\/code> line, reorder the file, or move the logic into a subshell, the guarantee still holds. Relying on the script&rsquo;s exit-on-error behavior to enforce the ordering is fragile by comparison, because the protection then lives outside the lines that matter.<\/p>\n<p><strong>Adjust the <code>PATH<\/code> line if your <code>command -v<\/code> output showed a different directory<\/strong> \u2014 append it to the list. If you would rather not set <code>PATH<\/code> at all, replace each bare command name with the absolute path you found (for example <code>\/usr\/bin\/rsync -a \"$SRC\/\" \"$DEST\/\"<\/code>); the two approaches are equivalent, and either one satisfies cron.<\/p>\n<p><strong>Trade-off, stated honestly:<\/strong><\/p>\n<ul>\n<li>Option A, as written, copies the source into the destination and keeps destination-only files. It is cheap in space and safe against a missing, unreadable, or empty source, but it does not track deletions, and \u2014 like any single-version copy that overwrites in place \u2014 it keeps no earlier version of its own, so if a file is corrupted at the source, the next run copies the corrupted version over the good copy in <code>DEST<\/code>.<\/li>\n<li>Option B accumulates dated archives and rotates them on the same schedule, keeping roughly <code>RETAIN_DAYS<\/code> days of history and removing only the archives this script created. Earlier states remain recoverable until the rotation line removes them.<\/li>\n<\/ul>\n<p><strong>Consistency caveat for Option B \u2014 do not call it a snapshot:<\/strong> the archive is <em>timestamped<\/em>, not guaranteed consistent. If files are being written while <code>tar<\/code> reads them, the archive may capture some files before a change and others after, so it may not represent one single moment in time. A genuinely consistent point-in-time image requires a snapshot mechanism \u2014 an LVM or filesystem snapshot, for example \u2014 or quiescing writes to the source while the archive runs. Neither is built into the script above.<\/p>\n<p><strong>One more cron-specific note:<\/strong> cron sets <code>HOME<\/code> to the user&rsquo;s home directory, so <code>$HOME<\/code> resolves correctly. If you ever see the script write to an unexpected location, replace <code>$HOME<\/code> with the literal path (for example <code>\/home\/youruser<\/code>).<\/p>\n<h4 id=\"if-you-need-an-exact-mirror-using-delete-safely\">If you need an exact mirror: using <code>--delete<\/code> safely<\/h4>\n<p>Skip this unless you are adding <code>--delete<\/code>. The source checks above do <strong>not<\/strong> make that flag safe.<\/p>\n<p><strong>What the checks do and do not catch.<\/strong> Existence, readability, and emptiness cover three situations: <code>SRC<\/code> is gone, <code>SRC<\/code> cannot be read, or <code>SRC<\/code> is completely empty. Each would otherwise let <code>--delete<\/code> empty your destination in one run. They do <strong>not<\/strong> catch a source that exists, is readable, and is partly populated \u2014 a network mount that is mounted but not yet fully readable, an upstream replication job that has only copied part of the data, a wrong-but-plausible path containing a few files, or a permissions problem hiding most of the tree. In all of those cases every check passes, and <code>--delete<\/code> removes every destination file the incomplete source doesn&rsquo;t account for. <strong>No simple check inside the script can prove the source is complete<\/strong>, because only you know what &ldquo;complete&rdquo; means for your data.<\/p>\n<p>If you still want <code>--delete<\/code>, do all three of these:<\/p>\n<ol>\n<li><strong>Gate it behind a sentinel you control.<\/strong> Place a marker file at the root of the source that exists only when the data set is fully present, then require it:<\/li>\n<\/ol>\n<p><code>bash<br \/>\n   if [ ! -f \"$SRC\/.backup-source-complete\" ]; then<br \/>\n     echo \"Completeness sentinel missing in $SRC; aborting before --delete.\" &gt;&amp;2<br \/>\n     exit 1<br \/>\n   fi<\/code><\/p>\n<p>This is stronger than the emptiness check, but only as reliable as the process that writes the marker. A stale marker from a previous run proves nothing.<\/p>\n<ol start=\"2\">\n<li><strong>Add a minimum-count check.<\/strong> Use the absolute paths your <code>command -v<\/code> run reported for both <code>find<\/code> and <code>wc<\/code>, so the check works even if your <code>PATH<\/code> differs:<\/li>\n<\/ol>\n<p><code>bash<br \/>\n   MIN_FILES=1000<br \/>\n   FIND=$(command -v find)<br \/>\n   WC=$(command -v wc)<br \/>\n   COUNT=$(\"$FIND\" \"$SRC\" -type f | \"$WC\" -l)<br \/>\n   if [ \"$COUNT\" -lt \"$MIN_FILES\" ]; then<br \/>\n     echo \"Only $COUNT files in $SRC (expected at least $MIN_FILES); aborting.\" &gt;&amp;2<br \/>\n     exit 1<br \/>\n   fi<\/code><\/p>\n<p>Set <code>MIN_FILES<\/code> from a real measurement of your source, not a guess. This catches a partial source that still looks plausible.<\/p>\n<ol start=\"3\">\n<li><strong>Dry-run before every destructive run, with verbose and itemized output.<\/strong> A plain <code>--dry-run<\/code> on its own is not enough: without verbose or itemized output, <code>rsync<\/code> generally prints no per-file list at all, so a silent dry run can look like &ldquo;nothing to do&rdquo; even when the real run would delete files. Add <code>-v<\/code> and <code>-i<\/code> so the dry run actually shows the plan:<\/li>\n<\/ol>\n<p><code>bash<br \/>\n   rsync -avni --delete \"$SRC\/\" \"$DEST\/\"<\/code><\/p>\n<p>Here <code>-n<\/code> is the dry run, <code>-v<\/code> makes it verbose, and <code>-i<\/code> (itemize-changes) prints one line per affected file. Nothing is touched. A dry run without <code>-v<\/code>\/<code>-i<\/code> \u2014 that is, a bare <code>--dry-run<\/code> \u2014 gives you no file-level output to review, so don&rsquo;t rely on it. <strong>How to read the output:<\/strong> every line starting with <code>*deleting<\/code> names a file or folder that would be removed from <code>DEST<\/code>. Lines starting with <code>&gt;f+++++++++<\/code> are new files that would be copied; <code>&gt;f.st......<\/code> marks a file whose size and timestamp differ; a trailing <code>*deleting<\/code> block is the list you are reviewing. If you see <code>*deleting<\/code> entries you did not intend \u2014 anything you expected to keep \u2014 stop, fix <code>SRC<\/code>, and run the dry run again. Run it whenever you change <code>SRC<\/code> or <code>DEST<\/code>, and the first time you set the job up. Remove <code>-n<\/code> (the dry-run flag) only when every reported deletion is one you actually want.<\/p>\n<p>Even with all three, <code>--delete<\/code> remains the most dangerous line in this guide. If you can live with a destination that keeps some stale files, omit the flag and skip this section.<\/p>\n<h3 id=\"step-4-test-the-script-manually-before-scheduling-it\">Step 4 \u2014 Test the script manually before scheduling it<\/h3>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code>chmod<span style=\"color: #BBB\"> <\/span>+x<span style=\"color: #BBB\"> <\/span>~\/scripts\/backup.sh\n~\/scripts\/backup.sh\nls<span style=\"color: #BBB\"> <\/span>-la<span style=\"color: #BBB\"> <\/span>~\/backups\/daily\n<\/code><\/pre>\n<\/div>\n<p><strong>Never register an untested script in crontab.<\/strong> Run it by hand at least once and verify the output looks right. If you used Option B, confirm the archive was created and that rotation did not remove anything you wanted to keep. If you added <code>--delete<\/code>, run the itemized dry run first, every time, and check that the reported deletions are ones you actually intend.<\/p>\n<h3 id=\"step-5-register-the-job-in-crontab\">Step 5 \u2014 Register the job in crontab<\/h3>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code>crontab<span style=\"color: #BBB\"> <\/span>-e\n<\/code><\/pre>\n<\/div>\n<p>Then a worked entry:<\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code><span style=\"color: #3D7B7B; font-style: italic\"># Run the backup every day at 02:30<\/span>\n<span style=\"color: #666\">30<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span><span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/scripts\/backup.sh<span style=\"color: #BBB\"> <\/span>&gt;&gt;<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/backups\/backup.log<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>\n<\/code><\/pre>\n<\/div>\n<p>Read the five fields left to right: <strong>minute<\/strong> (0\u201359), <strong>hour<\/strong> (0\u201323), <strong>day of month<\/strong> (1\u201331), <strong>month<\/strong> (1\u201312), <strong>day of week<\/strong> (0\u20137, Sunday is 0 or 7). The line above means 02:30 every day.<\/p>\n<p>Three alternate schedules, ready to paste:<\/p>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code><span style=\"color: #3D7B7B; font-style: italic\"># Every 6 hours<\/span>\n<span style=\"color: #666\">0<\/span><span style=\"color: #BBB\"> <\/span>*\/6<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/scripts\/backup.sh<span style=\"color: #BBB\"> <\/span>&gt;&gt;<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/backups\/backup.log<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>\n\n<span style=\"color: #3D7B7B; font-style: italic\"># Weekdays only, 03:00<\/span>\n<span style=\"color: #666\">0<\/span><span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">3<\/span><span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">1<\/span>-5<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/scripts\/backup.sh<span style=\"color: #BBB\"> <\/span>&gt;&gt;<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/backups\/backup.log<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>\n\n<span style=\"color: #3D7B7B; font-style: italic\"># Hourly, on the hour<\/span>\n<span style=\"color: #666\">0<\/span><span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>*<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/scripts\/backup.sh<span style=\"color: #BBB\"> <\/span>&gt;&gt;<span style=\"color: #BBB\"> <\/span>\/home\/youruser\/backups\/backup.log<span style=\"color: #BBB\"> <\/span><span style=\"color: #666\">2<\/span>&gt;&amp;<span style=\"color: #666\">1<\/span>\n<\/code><\/pre>\n<\/div>\n<p><strong>Critical cron gotchas:<\/strong><\/p>\n<ul>\n<li><strong>The crontab entry needs an absolute path to the script.<\/strong> Cron does not expand <code>~<\/code> and does not inherit your interactive shell&rsquo;s working directory, which is why the line reads <code>\/home\/youruser\/scripts\/backup.sh<\/code> rather than <code>~\/scripts\/backup.sh<\/code>. Substitute your real home path. The commands <em>inside<\/em> the script resolve through the <code>PATH<\/code> you set in Step 3, so the two halves agree \u2014 but the script itself still has to be found by cron.<\/li>\n<li><strong>Redirect output to a log<\/strong>, using an absolute path as above. Cron mails output by default, and most desktop setups have no mail agent, so failures vanish silently. This log is also where the scripts&rsquo; &ldquo;aborting&rdquo; messages appear if the source goes missing, becomes unreadable, empties, fails a sentinel or count check, or if Option B&rsquo;s archive creation fails.<\/li>\n<li>If you skipped the <code>PATH<\/code> line inside the script and used absolute command paths instead, no further crontab change is needed. If you did neither, set <code>SHELL<\/code> and <code>PATH<\/code> at the top of the crontab as a fallback.<\/li>\n<\/ul>\n<h3 id=\"step-6-verify-the-scheduled-job-actually-ran\">Step 6 \u2014 Verify the scheduled job actually ran<\/h3>\n<div class=\"highlight\" style=\"background: #f8f8f8\">\n<pre style=\"line-height: 125%;\"><span><\/span><code>grep<span style=\"color: #BBB\"> <\/span>CRON<span style=\"color: #BBB\"> <\/span>\/var\/log\/syslog<span style=\"color: #BBB\">          <\/span><span style=\"color: #3D7B7B; font-style: italic\"># Debian\/Ubuntu<\/span>\njournalctl<span style=\"color: #BBB\"> <\/span>-u<span style=\"color: #BBB\"> <\/span>cron<span style=\"color: #BBB\"> <\/span>--since<span style=\"color: #BBB\"> <\/span>today<span style=\"color: #BBB\">   <\/span><span style=\"color: #3D7B7B; font-style: italic\"># systemd systems<\/span>\ncat<span style=\"color: #BBB\"> <\/span>~\/backups\/backup.log\n<\/code><\/pre>\n<\/div>\n<p>Wait one full cycle rather than assuming. A cron job that is registered is not a cron job that is working. Confirm from the log that the run completed rather than aborting on a source check or, for Option B, on a failed archive.<\/p>\n<h3 id=\"step-7-install-the-nutstore-desktop-client\">Step 7 \u2014 Install the Nutstore desktop client<\/h3>\n<p>This step and Step 8 require a graphical desktop session on the machine holding the backup folder.<\/p>\n<ul>\n<li>Download and install the Nutstore desktop client for your OS. Nutstore ships clients for <strong>Linux, Windows, and macOS<\/strong> \u2014 relevant here because the backup-producing machine and the machine you read from need not match.<\/li>\n<li>Sign in to your account.<\/li>\n<li>Complete any first-run setup the client presents.<\/li>\n<\/ul>\n<p>Individual features may differ by platform, so check what your client build and plan offer rather than assuming a capability is present everywhere.<\/p>\n<h3 id=\"step-8-point-nutstore-at-the-backup-folder-using-arbitrary-folder-sync\">Step 8 \u2014 Point Nutstore at the backup folder using Arbitrary Folder Sync<\/h3>\n<p>This is the key step for this audience, and it is a desktop-client workflow: it assumes a file manager with a context menu on the machine that holds the backup folder.<\/p>\n<ol>\n<li>In your file manager, navigate to the folder your script writes to \u2014 <code>~\/backups\/daily<\/code> in our example.<\/li>\n<li><strong>Right-click the folder<\/strong> and choose the Nutstore sync option from the context menu.<\/li>\n<li>Confirm the sync.<\/li>\n<\/ol>\n<p>Some cloud drives require you to place content in a designated sync folder, or to fake it with <code>mklink<\/code>\/symlinks. <strong>Arbitrary Folder Sync removes that constraint<\/strong> \u2014 the script keeps writing to its natural path, and the client syncs that path in place. Nothing in the script changes, and no <code>mklink<\/code> command is involved.<\/p>\n<p>Because this step runs through the desktop client and a file manager, it does not apply to a machine you can only reach over SSH. If your cron job runs on a headless server, arrange for the script&rsquo;s output to land somewhere a desktop machine can access, and run Steps 7\u20139 on that desktop. Verify that arrangement yourself; this guide does not configure it.<\/p>\n<h3 id=\"step-9-verify-the-sync-from-another-device-and-understand-the-boundary-you-built\">Step 9 \u2014 Verify the sync from another device and understand the boundary you built<\/h3>\n<p>Let the initial upload complete (the first sync of a large backup set takes longest), then check the same folder from <strong>another supported device or the web app<\/strong>. At the point of action, the boundary is this: <strong>edits that are never saved or never uploaded will not be available through cloud sync.<\/strong> A file the client hasn&rsquo;t finished uploading is not yet reachable elsewhere.<\/p>\n<p>What your chosen option actually produced, because the options are not interchangeable:<\/p>\n<ul>\n<li><strong>Option A as written:<\/strong> the local folder accumulates copies of your source files. It does not track deletions, and it keeps no earlier versions, so a corrupted source file overwrites the good copy on the next run.<\/li>\n<li><strong><code>--delete<\/code> added:<\/strong> your destination becomes an exact mirror of the source, deletions included. An incomplete source can remove destination files, and the sentinel and count checks only reduce that risk rather than eliminating it.<\/li>\n<li><strong>Option B:<\/strong> dated archives, one per run, so earlier states remain recoverable until rotation removes them past the retention window \u2014 which is approximate, and applies only to archives matching this script&rsquo;s own naming pattern, leaving other files in the folder alone. How close each archive comes to a consistent point in time depends on whether anything was writing to the source while <code>tar<\/code> ran.<\/li>\n<li>In all cases, Nutstore carries that folder&rsquo;s <strong>current state<\/strong> to your other devices \u2014 delivery, not backup. A local deletion can propagate through sync, and an edit you make on your laptop flows back, which means the folder is live and shared, not frozen.<\/li>\n<\/ul>\n<p>Practical takeaway: keep a separate, non-synced copy of anything irreplaceable, and consider retaining version history where your plan provides it. <strong>Version history availability and retention depend on your plan<\/strong> \u2014 check yours rather than assuming.<\/p>\n<hr>\n<h2 id=\"troubleshooting-common-failures\">Troubleshooting Common Failures<\/h2>\n<p><strong>Quick answer:<\/strong> most failures trace to three checks. Confirm the crontab entry uses an absolute path to the script and read <code>~\/backups\/backup.log<\/code> for an &ldquo;aborting&rdquo; or &ldquo;command not found&rdquo; line; confirm the script&rsquo;s <code>DEST<\/code> is the same folder you right-clicked in Nutstore; and confirm the client shows sync as <strong>complete<\/strong>, not in progress. Work through those three before anything else.<\/p>\n<h3 id=\"issue-1-my-script-works-manually-but-cron-never-runs-it\">Issue 1 \u2014 &ldquo;My script works manually but cron never runs it&rdquo;<\/h3>\n<p><strong>Most likely cause:<\/strong> environment. Cron uses a minimal <code>PATH<\/code> and a different shell, so either the script itself can&rsquo;t be found or the tools it calls can&rsquo;t be found.<\/p>\n<p><strong>Fix:<\/strong> check both halves. First, confirm the crontab entry uses the absolute path to the script (<code>\/home\/youruser\/scripts\/backup.sh<\/code>, not <code>~\/scripts\/backup.sh<\/code>). Second, confirm the script sets a <code>PATH<\/code> that includes the directories your <code>command -v<\/code> check in Step 3 reported, or that every command inside it is written as an absolute path \u2014 including <code>wc<\/code>, if you added the minimum-count check. Then re-check the log for a &ldquo;command not found&rdquo; line.<\/p>\n<h3 id=\"issue-2-the-backup-ran-but-nothing-shows-up-on-my-other-devices\">Issue 2 \u2014 &ldquo;The backup ran, but nothing shows up on my other devices&rdquo;<\/h3>\n<p><strong>Most likely cause:<\/strong> the wrong folder is synced, the upload hasn&rsquo;t finished, or the file was never written where you think.<\/p>\n<p><strong>Fix:<\/strong> confirm the script&rsquo;s <code>DEST<\/code> variable and the folder you right-clicked are the same path. Confirm the client shows sync as complete, not in progress. If the script ran on a machine with no desktop session, Step 8 was never completed there. Files not yet uploaded are not available through cloud sync \u2014 expected behavior, not a bug.<\/p>\n<h3 id=\"issue-3-files-disappeared-from-my-destination-or-from-the-cloud-after-a-run\">Issue 3 \u2014 &ldquo;Files disappeared from my destination, or from the cloud, after a run&rdquo;<\/h3>\n<p>Three cases, told apart by where the files went missing:<\/p>\n<table>\n<thead>\n<tr>\n<th>Where files vanished<\/th>\n<th>Likely cause<\/th>\n<th>What to check<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>From <code>~\/backups\/daily<\/code> on the machine, with <code>--delete<\/code> enabled<\/td>\n<td>The source was incomplete, and the exact mirror reproduced the incompleteness<\/td>\n<td><code>~\/backups\/backup.log<\/code> for an &ldquo;aborting&rdquo; message. If there is none, the source passed every check while still being incomplete \u2014 the gap the exact-mirror guidance warns about. Tighten the sentinel or count threshold, or remove <code>--delete<\/code>.<\/td>\n<\/tr>\n<tr>\n<td>From the destination with Option A <strong>without<\/strong> <code>--delete<\/code>, or from Option B&rsquo;s archive set<\/td>\n<td>Should not come from <code>rsync<\/code> or a successful rotation<\/td>\n<td>Whether a manual cleanup or another tool touched the folder, and whether rotation removed archives past the retention window \u2014 but only archives matching this script&rsquo;s <code>documents_*.tar.gz<\/code> naming scheme are ever rotated, so unrelated files should be untouched<\/td>\n<\/tr>\n<tr>\n<td>From the cloud or another device, but still present locally<\/td>\n<td>Sync propagating a local deletion<\/td>\n<td>This is the single most important failure mode in this article<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Fix:<\/strong> in the first and third cases, neither the exact mirror nor sync is malfunctioning \u2014 an exact mirror reproduces the source exactly, and sync mirrors state, including deletions. Restore from your recycle bin or version history if your plan and retention window allow, restore from an Option B archive if you kept one, and then add a genuinely independent copy to your routine so the synced folder isn&rsquo;t your only protection.<\/p>\n<hr>\n<h2 id=\"frequently-asked-questions\">Frequently Asked Questions<\/h2>\n<p><strong>Q1. Can Nutstore run my cron job for me?<\/strong><br \/>\nNo. Nutstore does not execute scripts or schedule jobs. Cron (or your OS&rsquo;s scheduler) owns the scheduling; Nutstore handles moving the resulting folder to your other devices.<\/p>\n<p><strong>Q2. Is syncing a folder the same as backing it up?<\/strong><br \/>\nNo. Sync keeps a folder&rsquo;s current state consistent across devices, which means it can propagate changes and deletions. It does not give you an independent, separate copy that survives changes to the live folder.<\/p>\n<p><strong>Q3. Can I sync a folder without moving it into a special Nutstore directory?<\/strong><br \/>\nYes. <strong>Arbitrary Folder Sync<\/strong> lets you right-click any folder on the computer and sync it in place \u2014 no designated sync folder and no <code>mklink<\/code> command needed, which is why your script can keep writing to its normal path. This is done through the desktop client on a machine with a graphical session. One exception: don&rsquo;t use it to sync code repositories \u2014 <strong>Nutstore is not recommended for code sync<\/strong>, since it isn&rsquo;t a version control tool. Keep scripts and source trees in Git.<\/p>\n<p><strong>Q4. My backup output is a <code>.tar.gz<\/code> \u2014 will it upload efficiently?<\/strong><br \/>\nThe published documentation identifies compressed files (zip\/rar), images (jpg\/png), and video files as not supporting delta sync; it does not specifically confirm or rule out <code>.tar.gz<\/code> archives, so treat archive uploads as potentially full-file uploads and test with your own data rather than assuming. Separately, <strong>Delta Sync<\/strong> itself requires the original file to be over 64 KB, the delta to be under 70% of the original, and the delta to be under 10 MB, and it is available on the <strong>PC client only<\/strong>. If bandwidth matters, plain-file output (Option A) avoids the question entirely.<\/p>\n<p><strong>Q5. Can I run this whole workflow on a headless server?<\/strong><br \/>\nNot as described. The Nutstore half is done through the desktop client and a file manager&rsquo;s right-click menu, so it needs a graphical session on the machine holding the backup folder. The cron half runs fine on a headless server, but the sync setup in this guide does not cover that case.<\/p>\n<p><strong>Q6. What if I want a third-party app to read files from Nutstore?<\/strong><br \/>\n<strong>WebDAV<\/strong> is available as an integration option at <code>dav.jianguoyun.com\/dav\/<\/code> and works with compatible apps such as WPS, Zotero, PDF Expert, Notability, Joplin, and Keepass. Treat it as an integration path for apps that support WebDAV, not as a cron-based backup mechanism. Paid users are subject to a limit of 1,500 requests per 30 minutes.<\/p>\n<hr>\n<h2 id=\"summary\">Summary<\/h2>\n<ol>\n<li><strong>Cron produces the scheduled local backup.<\/strong> What that backup is depends on which option you chose \u2014 Option A keeps one-way, non-deleting copies of your source files without tracking deletions and without keeping earlier versions; adding <code>--delete<\/code> turns it into an exact mirror that an incomplete source can damage; Option B keeps dated archives that retain earlier states until rotation removes them past the (approximate) retention window, and that rotation runs only after a successful archive and only on archives matching this script&rsquo;s own naming pattern.<\/li>\n<li><strong>Nutstore syncs the resulting folder to your other devices<\/strong> \u2014 that&rsquo;s delivery.<\/li>\n<li><strong>Sync is not an independent backup<\/strong>, and unsaved or unuploaded edits aren&rsquo;t protected.<\/li>\n<\/ol>\n<p>What you built: a hands-off script that runs on a schedule with a <code>PATH<\/code> cron can actually resolve and source checks that fail safely, a folder that syncs in place via right-click without <code>mklink<\/code> or a special directory, and access from another supported device or the web \u2014 with the desktop-client setup done on a machine that has a graphical session.<\/p>\n<hr>\n<h2 id=\"try-nutstore-today\">Try Nutstore Today<\/h2>\n<p><strong>Setting this up for a team rather than a single machine?<\/strong> The <strong>Nutstore Team plan includes a 20-day free trial<\/strong>.<br \/>\n\ud83d\udc49 <a href=\"https:\/\/www.jianguoyun.com\/s\/campaign\/cpclanding\/team?sch=AIcb\">Start the Nutstore Team free trial<\/a><\/p>\n<p><strong>Just want the desktop client for your own Linux, Windows, or macOS machine?<\/strong> Start here.<br \/>\n\ud83d\udc49 <a href=\"https:\/\/www.jianguoyun.com\/s\/campaign\/cpclanding\/main?sch=AIcb\">Get Nutstore<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use cron to schedule a Linux backup script, then sync its output folder to other devices with Nutstore\u2019s Arbitrary Folder Sync. This step-by-step guide covers script options, crontab setup, testing, and troubleshooting\u2014and explains why cloud sync is not an independent backup and can propagate deletions.<\/p>\n","protected":false},"author":1,"featured_media":562,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[95,94],"tags":[49,464,13,463,12,465],"_links":{"self":[{"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/posts\/563"}],"collection":[{"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=563"}],"version-history":[{"count":0,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/posts\/563\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=\/wp\/v2\/media\/562"}],"wp:attachment":[{"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jianguoyun.com\/en\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}