I am running my Raspberry 24/7 and would like to use a backup-script on a daily basis via a cronjob. That script puts certain contents together in an archive and should then store the archive somewhere. Can I just use a simple 8GB USB-Stick or is it better to use a SSD for example or a cloud based solution to push the archive, have it online?

  • Define better? Faster, Cost, etc. Apr 12 '20 at 20:58
  • I am already owning a SSD and a USB-Stick, so cost should be zero, concerning speed, there are no specific requirements. It is just one RaspberryPi Model 3 Model B. Apr 12 '20 at 21:03

Yes - you can use a simple 8GB USB-Stick. That's what I do. I'm guessing you already know how to set this up, but to make this a more complete answer, here's an outline. If you have any questions, suggest you edit your question & leave a comment to my answer.

  1. Format your USB drive as ext4, then make an entry in /etc/fstab. Here's an example:
LABEL=SANDISK8GB /home/pi/mntBackupDrv ext4 rw,user,nofail 0 0
  1. Decide what files & folders you want to back up, then create a bash script that uses rsync to perform the backup. Here's an example script:

rsync -av -F --delete /home/pi/ /home/pi/mntBackupDrv/rpi3b_backup/home/ >> /home/pi/mntBackupDrv/rpi3b_backup/home/rsync_home_backup.txt && \
/bin/echo -e "\nrsync completed: $(date)\n" >> /home/pi/mntBackupDrv/rpi3b_backup/home/rsync_home_backup.txt

The script is fairly simple. /home/pi is the source, my USB thumb drive is the destination. The activity is logged to a file that's also on the USB drive along with a time stamp.

Read man rsync for an explanation of the options; the -F simply excludes some files & folders defined in files named .rsync-filter.

If you want this stored an archive (tar), and maybe compressed, you could add that to the script - or use it instead of rsync.

You should run this script manually to make sure it does what you want it to do before you schedule it with cron. Also consider the use of the --dry-run option in rsync to verify that.

  1. Schedule your script to run using crontab -e. You could do something like this to backup your /home/pi folder:
#----------- BACKUP `/home/pi` WITH `rsync` AT ./mntBackupDrv -----------
# NOTE: See root's crontab for the backup of /etc
55 1 * * * crontab -l > /home/pi/crontab_listing_home.txt
0 2 * * * /home/pi/bkup_pihome.sh

Notes re crontab:

  • This runs two jobs:
    • at 01:55 each day, contents of the crontab are output to a file (this backs up my crontab)
    • at 02:00 each day, the script /home/pi/bkup_pihome.sh is run (see above for listing).
  • No sudo required for backing up /home/pi
  • I also backup a few files in /etc - anything I might have changed extensively or frequently. That's not very many files, btw. That requires sudo; I do that with root's crontab; i.e. sudo crontab -e, and a separate script.


I'd like to include this excellent reference for Using rsync and cron to automate incremental backups. There are several ideas relevant to a backup strategy in this post worth consideration.

  • Thank you so far. For formatting I used tecadmin.net/format-usb-in-linux \n What is the effect for the usb drive of the entry in /etc/fstab? Apr 15 '20 at 19:52
  • Concerning scheduling with a cronjob and the backup-script I got everything together, though I had to use the crontab of root sudo su - + crontab -e since I want to backup folders in /etc as well. Did not use rsync just tar the content together. Apr 15 '20 at 19:55
  • One point - if you use ext4 for the format, you are basically forcing yourself to use Linux or extra drivers to read the USB stick. Formatting the stick as ExFAT allows Macs and PCs to read your backup data if you need to. The addition of ExFat on the Pi is documented all over (e.g. pimylifeup.com/raspberry-pi-exfat) also think about how you remove the backup - you need to make sure the data is written to the USB stick before pulling it - a backup in the same physical location is not a solid idea :-)
    – user115418
    Apr 15 '20 at 20:53
  • @Andyroo: True, but for me, ext4 is the way to go. Storing backups on ExFAT seems a bit like keeping my money under the mattress :) But all kidding aside - yeah - if cross-platform access to your backups is an important consideration, then exFAT might fit the bill. And yes - always umount a mounted drive before pulling it from a running system.
    – Seamus
    Apr 15 '20 at 21:33
  • @Marius: Entry in /etc/fstab only means that when you "plug in" that particular USB drive, it is mounted by the system automatically. The alternative is to manually mount the drive before you use it.
    – Seamus
    Apr 15 '20 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.