How to Automate Cron Backup on Linux and Sync to Cloud

Cron schedules the backup. Nutstore gets the result onto your other devices. These are two separate jobs — and mixing them up is how people lose data.

Nutstore does not run your cron jobs or execute scripts. Sync is not an independent backup — 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 not recommended for code sync.

This guide covers machines with a graphical desktop environment — Linux, Windows, or macOS. The Nutstore half is set up through the desktop client and a file manager’s right-click menu, so headless servers are outside what it demonstrates.


What You’ll Need Before You Start

On the Linux machine (or any supported desktop OS):

  • A Linux desktop distribution with a graphical environment and cron / crontab available (pre-installed on most distros; verify with crontab -l and systemctl status cron or systemctl status crond).
  • A shell account with permission to edit its own crontab — no root needed for user-level jobs.
  • Enough free disk space for at least 2–3 rotations of your backup set.
  • Basic familiarity with a terminal and a text editor (nano, vim, etc.).

For the sync half:

  • A Nutstore account.
  • The Nutstore desktop client installed on the machine that holds the backup folder, on a desktop session where you can complete the client’s setup. Nutstore ships desktop clients for Windows, macOS, and Linux — one of the few domestic providers with full-platform support — so the machine writing the backups and the machine reading them don’t need to run the same OS.
  • At least one other supported device or browser access to verify the files arrived.

What you do not need:

  • No mklink, no symlinks, no relocating files into a designated sync directory. Arbitrary Folder Sync lets you right-click an existing folder — including the one your script writes to — and sync it in place.
  • No Nutstore-side scheduling configuration. There isn’t any.

Platform/plan caveat: Specific features differ by platform and plan. Confirm what your plan includes before building a workflow around it.


Step-by-Step Configuration Guide

Step 1 — Decide what a “backup” means for your case

Three things get conflated in this topic. Separate them first.

Term What it actually does
Scheduled local backup 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.
Sync A client mirrors a folder’s current state to the cloud and to other devices. If a file is deleted locally, that deletion can propagate.
Independent backup A separate copy that does not track the live folder’s changes.

The two script options below produce different kinds of local output: 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 sync does not replace an independent backup.

Step 2 — Create the destination and script folders

mkdir -p ~/backups/daily
mkdir -p ~/scripts

Put the destination somewhere stable that won’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: share links break if the source file or folder is moved or renamed, so pick a final path now rather than reorganizing later.

Step 3 — Create a cron backup script on Linux

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.

First, locate the external commands the script will call. Cron runs with a minimal environment, so run this in your normal shell:

command -v rsync tar date mkdir find wc dirname basename

Each line of output is that program’s absolute path — for example /usr/bin/rsync, /usr/bin/tar, /bin/mkdir, /usr/bin/find, /usr/bin/wc. On most distributions these sit in /usr/bin and /bin. If any command lives elsewhere, note the directory, because you will put it on the script’s PATH. wc matters in particular, because the exact-mirror guidance below uses it.

The scripts set their own PATH rather than relying on whatever cron hands them. The alternative — calling every tool by absolute path — works too, but makes the scripts harder to read.

Create the script file at the path Step 2 prepared:

nano ~/scripts/backup.sh

Option A — one-way, non-deleting copy with rsync (fast, space-efficient; copies the source into the destination without deleting destination-only files):

#!/bin/bash
# ~/scripts/backup.sh
set -euo pipefail

# cron runs with a minimal environment; set a PATH containing the tools called below.
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SRC="$HOME/documents"          # what you want backed up
DEST="$HOME/backups/daily"     # what Nutstore will sync

# Source checks. Each one fails safely and says why.
if [ ! -d "$SRC" ]; then
  echo "Source directory $SRC does not exist; aborting." >&2
  exit 1
fi
if [ ! -r "$SRC" ] || ! ls -A "$SRC" >/dev/null 2>&1; then
  echo "Source directory $SRC is not readable; aborting." >&2
  exit 1
fi
if [ -z "$(ls -A "$SRC")" ]; then
  echo "Source directory $SRC is empty; aborting." >&2
  exit 1
fi

mkdir -p "$DEST"
rsync -a "$SRC/" "$DEST/"

Why the readability check comes before the emptiness check. A plain ls -A test alone cannot tell “empty” apart from “unreadable”: if the directory cannot be listed, the command fails, and the naive test treats that failure as emptiness or prints a misleading reason. Testing -r and the exit status of ls 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.

Why there is no --delete here. Notice the rsync line copies files into DEST but never removes anything from it. That is deliberate, and it is the recommended default. Adding --delete makes the destination match the source exactly — which also means it deletes anything in the destination that isn’t in the source. Leave it off unless you have a specific reason to mirror exactly and you understand the risk, which is covered below.

What you give up by omitting --delete: if you delete a file from SRC, the copy in DEST stays behind, so the destination grows stale rather than tracking the source precisely. For a backup folder that is usually the safer trade — a stale extra file costs disk space, while a wrongly deleted file costs data.

Option B — timestamped archive (keeps a dated copy per run, larger, better rotation story):

#!/bin/bash
# ~/scripts/backup.sh
set -euo pipefail

# cron runs with a minimal environment; set a PATH containing the tools called below.
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SRC="$HOME/documents"
DEST="$HOME/backups/daily"
STAMP=$(date +%Y-%m-%d_%H%M%S)
RETAIN_DAYS=14
RETAIN_MIN=$((RETAIN_DAYS * 1440))   # retention window expressed in minutes

# Same source checks as Option A, for the same reasons.
if [ ! -d "$SRC" ]; then
  echo "Source directory $SRC does not exist; aborting." >&2
  exit 1
fi
if [ ! -r "$SRC" ] || ! ls -A "$SRC" >/dev/null 2>&1; then
  echo "Source directory $SRC is not readable; aborting." >&2
  exit 1
fi
if [ -z "$(ls -A "$SRC")" ]; then
  echo "Source directory $SRC is empty; aborting." >&2
  exit 1
fi

mkdir -p "$DEST"

# Rotate only after a successful archive, so a failed backup never deletes history.
# Only this script's own archives (documents_*.tar.gz) are eligible for removal.
if tar -czf "$DEST/documents_$STAMP.tar.gz" -C "$(dirname "$SRC")" "$(basename "$SRC")"; then
  find "$DEST" -name 'documents_*.tar.gz' -mmin +"$RETAIN_MIN" -delete
else
  echo "Archive creation failed; skipping rotation." >&2
  exit 1
fi

Where the cleanup line goes, and why. The find line sits inside the if, immediately after a successful tar. It never runs unless the archive was created. Two details in that line are deliberate and worth understanding before you change them:

  • The pattern is -name 'documents_*.tar.gz', not -name '*.tar.gz'. Only archives this script itself created — the ones matching the documents_<timestamp>.tar.gz naming scheme from the tar line — are eligible for removal. If you keep unrelated compressed backups in the same folder, they are left untouched; a bare *.tar.gz pattern would instead delete those too once they aged past the cutoff, which is rarely what you want.
  • The age test is -mmin +"$RETAIN_MIN", where RETAIN_MIN=$((RETAIN_DAYS * 1440)). With RETAIN_DAYS=14, that evaluates to -mmin +20160, meaning “older than about 20160 minutes, that is, roughly 14 days.” Treat that as approximate, not exact: GNU find truncates each file’s age to whole minutes before applying +N, so +20160 selects files at least 20161 minutes old — 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 find ... -newermt against a computed reference date) instead of relying on -mmin rounding. Do not swap in -mtime +14 expecting the same behavior either: GNU find’s -mtime rounds each file’s age down to whole 24-hour periods before comparing, so -mtime +14 actually selects files at least 15 full days old, not files older than 14 days. If you prefer -mtime for readability, remember the window is effectively one day wider than the number suggests.

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 RETAIN_DAYS to widen or narrow that window, and note that -delete is permanent.

Why the if wrapper instead of a plain sequential line. 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 — if you later add || true to the tar line, reorder the file, or move the logic into a subshell, the guarantee still holds. Relying on the script’s exit-on-error behavior to enforce the ordering is fragile by comparison, because the protection then lives outside the lines that matter.

Adjust the PATH line if your command -v output showed a different directory — append it to the list. If you would rather not set PATH at all, replace each bare command name with the absolute path you found (for example /usr/bin/rsync -a "$SRC/" "$DEST/"); the two approaches are equivalent, and either one satisfies cron.

Trade-off, stated honestly:

  • 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 — like any single-version copy that overwrites in place — 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 DEST.
  • Option B accumulates dated archives and rotates them on the same schedule, keeping roughly RETAIN_DAYS days of history and removing only the archives this script created. Earlier states remain recoverable until the rotation line removes them.

Consistency caveat for Option B — do not call it a snapshot: the archive is timestamped, not guaranteed consistent. If files are being written while tar 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 — an LVM or filesystem snapshot, for example — or quiescing writes to the source while the archive runs. Neither is built into the script above.

One more cron-specific note: cron sets HOME to the user’s home directory, so $HOME resolves correctly. If you ever see the script write to an unexpected location, replace $HOME with the literal path (for example /home/youruser).

If you need an exact mirror: using --delete safely

Skip this unless you are adding --delete. The source checks above do not make that flag safe.

What the checks do and do not catch. Existence, readability, and emptiness cover three situations: SRC is gone, SRC cannot be read, or SRC is completely empty. Each would otherwise let --delete empty your destination in one run. They do not catch a source that exists, is readable, and is partly populated — 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 --delete removes every destination file the incomplete source doesn’t account for. No simple check inside the script can prove the source is complete, because only you know what “complete” means for your data.

If you still want --delete, do all three of these:

  1. Gate it behind a sentinel you control. Place a marker file at the root of the source that exists only when the data set is fully present, then require it:

bash
if [ ! -f "$SRC/.backup-source-complete" ]; then
echo "Completeness sentinel missing in $SRC; aborting before --delete." >&2
exit 1
fi

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.

  1. Add a minimum-count check. Use the absolute paths your command -v run reported for both find and wc, so the check works even if your PATH differs:

bash
MIN_FILES=1000
FIND=$(command -v find)
WC=$(command -v wc)
COUNT=$("$FIND" "$SRC" -type f | "$WC" -l)
if [ "$COUNT" -lt "$MIN_FILES" ]; then
echo "Only $COUNT files in $SRC (expected at least $MIN_FILES); aborting." >&2
exit 1
fi

Set MIN_FILES from a real measurement of your source, not a guess. This catches a partial source that still looks plausible.

  1. Dry-run before every destructive run, with verbose and itemized output. A plain --dry-run on its own is not enough: without verbose or itemized output, rsync generally prints no per-file list at all, so a silent dry run can look like “nothing to do” even when the real run would delete files. Add -v and -i so the dry run actually shows the plan:

bash
rsync -avni --delete "$SRC/" "$DEST/"

Here -n is the dry run, -v makes it verbose, and -i (itemize-changes) prints one line per affected file. Nothing is touched. A dry run without -v/-i — that is, a bare --dry-run — gives you no file-level output to review, so don’t rely on it. How to read the output: every line starting with *deleting names a file or folder that would be removed from DEST. Lines starting with >f+++++++++ are new files that would be copied; >f.st...... marks a file whose size and timestamp differ; a trailing *deleting block is the list you are reviewing. If you see *deleting entries you did not intend — anything you expected to keep — stop, fix SRC, and run the dry run again. Run it whenever you change SRC or DEST, and the first time you set the job up. Remove -n (the dry-run flag) only when every reported deletion is one you actually want.

Even with all three, --delete 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.

Step 4 — Test the script manually before scheduling it

chmod +x ~/scripts/backup.sh
~/scripts/backup.sh
ls -la ~/backups/daily

Never register an untested script in crontab. 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 --delete, run the itemized dry run first, every time, and check that the reported deletions are ones you actually intend.

Step 5 — Register the job in crontab

crontab -e

Then a worked entry:

# Run the backup every day at 02:30
30 2 * * * /home/youruser/scripts/backup.sh >> /home/youruser/backups/backup.log 2>&1

Read the five fields left to right: minute (0–59), hour (0–23), day of month (1–31), month (1–12), day of week (0–7, Sunday is 0 or 7). The line above means 02:30 every day.

Three alternate schedules, ready to paste:

# Every 6 hours
0 */6 * * * /home/youruser/scripts/backup.sh >> /home/youruser/backups/backup.log 2>&1

# Weekdays only, 03:00
0 3 * * 1-5 /home/youruser/scripts/backup.sh >> /home/youruser/backups/backup.log 2>&1

# Hourly, on the hour
0 * * * * /home/youruser/scripts/backup.sh >> /home/youruser/backups/backup.log 2>&1

Critical cron gotchas:

  • The crontab entry needs an absolute path to the script. Cron does not expand ~ and does not inherit your interactive shell’s working directory, which is why the line reads /home/youruser/scripts/backup.sh rather than ~/scripts/backup.sh. Substitute your real home path. The commands inside the script resolve through the PATH you set in Step 3, so the two halves agree — but the script itself still has to be found by cron.
  • Redirect output to a log, 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’ “aborting” messages appear if the source goes missing, becomes unreadable, empties, fails a sentinel or count check, or if Option B’s archive creation fails.
  • If you skipped the PATH line inside the script and used absolute command paths instead, no further crontab change is needed. If you did neither, set SHELL and PATH at the top of the crontab as a fallback.

Step 6 — Verify the scheduled job actually ran

grep CRON /var/log/syslog          # Debian/Ubuntu
journalctl -u cron --since today   # systemd systems
cat ~/backups/backup.log

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.

Step 7 — Install the Nutstore desktop client

This step and Step 8 require a graphical desktop session on the machine holding the backup folder.

  • Download and install the Nutstore desktop client for your OS. Nutstore ships clients for Linux, Windows, and macOS — relevant here because the backup-producing machine and the machine you read from need not match.
  • Sign in to your account.
  • Complete any first-run setup the client presents.

Individual features may differ by platform, so check what your client build and plan offer rather than assuming a capability is present everywhere.

Step 8 — Point Nutstore at the backup folder using Arbitrary Folder Sync

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.

  1. In your file manager, navigate to the folder your script writes to — ~/backups/daily in our example.
  2. Right-click the folder and choose the Nutstore sync option from the context menu.
  3. Confirm the sync.

Some cloud drives require you to place content in a designated sync folder, or to fake it with mklink/symlinks. Arbitrary Folder Sync removes that constraint — the script keeps writing to its natural path, and the client syncs that path in place. Nothing in the script changes, and no mklink command is involved.

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’s output to land somewhere a desktop machine can access, and run Steps 7–9 on that desktop. Verify that arrangement yourself; this guide does not configure it.

Step 9 — Verify the sync from another device and understand the boundary you built

Let the initial upload complete (the first sync of a large backup set takes longest), then check the same folder from another supported device or the web app. At the point of action, the boundary is this: edits that are never saved or never uploaded will not be available through cloud sync. A file the client hasn’t finished uploading is not yet reachable elsewhere.

What your chosen option actually produced, because the options are not interchangeable:

  • Option A as written: 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.
  • --delete added: 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.
  • Option B: dated archives, one per run, so earlier states remain recoverable until rotation removes them past the retention window — which is approximate, and applies only to archives matching this script’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 tar ran.
  • In all cases, Nutstore carries that folder’s current state to your other devices — 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.

Practical takeaway: keep a separate, non-synced copy of anything irreplaceable, and consider retaining version history where your plan provides it. Version history availability and retention depend on your plan — check yours rather than assuming.


Troubleshooting Common Failures

Quick answer: most failures trace to three checks. Confirm the crontab entry uses an absolute path to the script and read ~/backups/backup.log for an “aborting” or “command not found” line; confirm the script’s DEST is the same folder you right-clicked in Nutstore; and confirm the client shows sync as complete, not in progress. Work through those three before anything else.

Issue 1 — “My script works manually but cron never runs it”

Most likely cause: environment. Cron uses a minimal PATH and a different shell, so either the script itself can’t be found or the tools it calls can’t be found.

Fix: check both halves. First, confirm the crontab entry uses the absolute path to the script (/home/youruser/scripts/backup.sh, not ~/scripts/backup.sh). Second, confirm the script sets a PATH that includes the directories your command -v check in Step 3 reported, or that every command inside it is written as an absolute path — including wc, if you added the minimum-count check. Then re-check the log for a “command not found” line.

Issue 2 — “The backup ran, but nothing shows up on my other devices”

Most likely cause: the wrong folder is synced, the upload hasn’t finished, or the file was never written where you think.

Fix: confirm the script’s DEST 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 — expected behavior, not a bug.

Issue 3 — “Files disappeared from my destination, or from the cloud, after a run”

Three cases, told apart by where the files went missing:

Where files vanished Likely cause What to check
From ~/backups/daily on the machine, with --delete enabled The source was incomplete, and the exact mirror reproduced the incompleteness ~/backups/backup.log for an “aborting” message. If there is none, the source passed every check while still being incomplete — the gap the exact-mirror guidance warns about. Tighten the sentinel or count threshold, or remove --delete.
From the destination with Option A without --delete, or from Option B’s archive set Should not come from rsync or a successful rotation Whether a manual cleanup or another tool touched the folder, and whether rotation removed archives past the retention window — but only archives matching this script’s documents_*.tar.gz naming scheme are ever rotated, so unrelated files should be untouched
From the cloud or another device, but still present locally Sync propagating a local deletion This is the single most important failure mode in this article

Fix: in the first and third cases, neither the exact mirror nor sync is malfunctioning — 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’t your only protection.


Frequently Asked Questions

Q1. Can Nutstore run my cron job for me?
No. Nutstore does not execute scripts or schedule jobs. Cron (or your OS’s scheduler) owns the scheduling; Nutstore handles moving the resulting folder to your other devices.

Q2. Is syncing a folder the same as backing it up?
No. Sync keeps a folder’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.

Q3. Can I sync a folder without moving it into a special Nutstore directory?
Yes. Arbitrary Folder Sync lets you right-click any folder on the computer and sync it in place — no designated sync folder and no mklink 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’t use it to sync code repositories — Nutstore is not recommended for code sync, since it isn’t a version control tool. Keep scripts and source trees in Git.

Q4. My backup output is a .tar.gz — will it upload efficiently?
The 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 .tar.gz archives, so treat archive uploads as potentially full-file uploads and test with your own data rather than assuming. Separately, Delta Sync 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 PC client only. If bandwidth matters, plain-file output (Option A) avoids the question entirely.

Q5. Can I run this whole workflow on a headless server?
Not as described. The Nutstore half is done through the desktop client and a file manager’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.

Q6. What if I want a third-party app to read files from Nutstore?
WebDAV is available as an integration option at dav.jianguoyun.com/dav/ 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.


Summary

  1. Cron produces the scheduled local backup. What that backup is depends on which option you chose — Option A keeps one-way, non-deleting copies of your source files without tracking deletions and without keeping earlier versions; adding --delete 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’s own naming pattern.
  2. Nutstore syncs the resulting folder to your other devices — that’s delivery.
  3. Sync is not an independent backup, and unsaved or unuploaded edits aren’t protected.

What you built: a hands-off script that runs on a schedule with a PATH cron can actually resolve and source checks that fail safely, a folder that syncs in place via right-click without mklink or a special directory, and access from another supported device or the web — with the desktop-client setup done on a machine that has a graphical session.


Try Nutstore Today

Setting this up for a team rather than a single machine? The Nutstore Team plan includes a 20-day free trial.
👉 Start the Nutstore Team free trial

Just want the desktop client for your own Linux, Windows, or macOS machine? Start here.
👉 Get Nutstore

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top