this post was submitted on 15 Oct 2024
134 points (99.3% liked)

Linux

47730 readers
852 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
134
submitted 22 hours ago* (last edited 22 hours ago) by mfat@lemdro.id to c/linux@lemmy.ml
 

Can you please share your backup strategies for linux? I'm curious to know what tools you use and why?How do you automate/schedule backups? Which files/folders you back up? What is your prefered hardware/cloud storage and how do you manage storage space?

top 50 comments
sorted by: hot top controversial new old
[–] toastal@lemmy.ml 3 points 3 hours ago

One reason for moving to Nix was declarative config so at least that part of my system is a series of Nix files to build into a working setup.

…The rest… let’s just say “needs improvement” & I would like to set up a NAS.

[–] joel1974@lemmy.world 4 points 4 hours ago

Not to save stuff

[–] sntx@lemm.ee 3 points 4 hours ago

I'm using rustic, a lock-free rust-written drop-in-replacement of restic, which (I'm referring to restic and therefore in extension to rustic) supports always-encrypted, deduplicating, compressed and easy backups without you needing to worry about whether to do a full- or incremental-backup.

All my machines run hourly backups of all mounted partitions to an append-only repo at borgbase. I have a file with ignore pattern globs to skip unwanted files and dirs (i.e.: **/.cache).

While I think borgbase is ok, ther're just using hetzner storage boxes in the background, which are cheaper if you use them directly. I'm thinking of migrating my backups to a handfull of homelabs from trusted friends and family instead.

The backups have a randomized delay of 5m and typically take about 8-9s each (unless big new files need to be uploaded). They are triggered by persistent systemd-timers.

The backups have been running across my laptop, pc and server for about 6 months now and I'm at ~380 GiB storage usage total.

I've mounted backup snapshots on multiple occasions already to either get an old version of a file, or restore it entirely.

There is a tool called redu which is like ncdu but works on restic/rustic repos. This makes it easy to identify which files blow up your backup size.

[–] _spiffy@lemmy.ca 6 points 6 hours ago (1 children)

Dump configs to backup drive. Pray to the machine spirit that things don't blow up. Only update when I remember. I'm a terrible admin for my own stuff.

[–] simonced@lemmy.one 1 points 6 hours ago

Thanks to you, I don't need to answer to OP anymore👍

[–] CynicusRex@slrpnk.net 1 points 5 hours ago
  1. Work in a cloud synced folder by default.

That's all my step 🦥

[–] Nomad@infosec.pub 2 points 7 hours ago

Bareos. Its a newer Form of bacula and is a realworkhorse.

[–] fireshell@lemmy.ml 2 points 7 hours ago

Example of a Bash script that performs the following tasks

  1. Checks the availability of an important web server.
  2. Checks disk space usage.
  3. Makes a backup of the specified directories.
  4. Sends a report to the administrator's email.

Example script:

#!/bin/bash

# Settings
WEB_SERVER="https://example.com"
BACKUP_DIR="/backup"
TARGET_DIRS="/var/www /etc"
DISK_USAGE_THRESHOLD=90
ADMIN_EMAIL="admin@example.com"
DATE=$(date +"%Y-%m-%d")
BACKUP_FILE="$BACKUP_DIR/backup-$DATE.tar.gz"

# Checking web server availability
echo "Checking web server availability..."
if curl -s --head $WEB_SERVER | grep "200 OK" > /dev/null; then
echo "Web server is available."
else
echo "Warning: Web server is unavailable!" | mail -s "Problem with web server" $ADMIN_EMAIL
fi

# Checking disk space
echo "Checking disk space..."
DISK_USAGE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
if [ $DISK_USAGE -gt $DISK_USAGE_THRESHOLD ]; then
echo "Warning: Disk space usage exceeded $DISK_USAGE_THRESHOLD%!" | mail -s "Problem with disk space" $ADMIN_EMAIL
else
echo "There is enough disk space."
fi

# Creating backup
echo "Creating backup..."
tar -czf $BACKUP_FILE $TARGET_DIRS

if [ $? -eq 0 ]; then
echo "Backup created successfully: $BACKUP_FILE"
else
echo "Error creating backup!" | mail -s "Error creating backup" $ADMIN_EMAIL
fi

# Sending report
echo "Sending report to $ADMIN_EMAIL..."
REPORT="Report for $DATE\n\n"
REPORT+="Web server status: $(curl -s --head $WEB_SERVER | head -n 1)\n"
REPORT+="Disk space usage: $DISK_USAGE%\n"
REPORT+="Backup location: $BACKUP_FILE\n"

echo -e $REPORT | mail -s "Daily system report" $ADMIN_EMAIL

echo "Done."

Description:

  1. Check web server: Uses curl command to check if the site is available.
  2. Check disk space: Use df and awk to check disk usage. If the threshold (90%) is exceeded, a notification is sent.
  3. Create a backup: The tar command archives and compresses the directories specified in the TARGET_DIRS variable.
  4. Send a report: A report on all operations is sent to the administrator's email using mail.

How to use:

  1. Set the desired parameters, such as the web server address, directories for backup, disk usage threshold and email.
  2. Make the script executable:
chmod +x /path/to/your/script.sh
  1. Add the script to cron to run on a regular basis:
crontab -e

Example to run every day at 00:00:

0 0 * * * /path/to/your/script.sh
[–] vortexal@lemmy.ml 3 points 11 hours ago (1 children)

The only thing I use as a backup is a Live CD that's mounted to a USB thumb drive.

I used to use Timeshift but the one time I needed it, it didn't work for some reason. It also had a problem of making my PC temporarily unusable while it was making a backup, so I didn't enable it when I had to reinstall Linux Mint.

[–] Teppichbrand@feddit.org 2 points 5 hours ago

Same, Timeshift let me down one time when I needed it. I still use it though, and I'm afraid to upgrade Mint because I don't want to set my system again for of the upgrade fails to keep my configuration and Timeshift fails to take me back

[–] fmstrat@lemmy.nowsci.com 1 points 8 hours ago

All important files go in /data.

/data is ZFS, snapped and sent to NAS regularly

Every time I change a setting, it gets added to a dconf script. Every time I install software, I write a script.

Dotfiles git repo for home directory.

With that, I can spin up a fresh machine in minutes with scripts.

[–] shapis@lemmy.ml 13 points 15 hours ago

All my code and projects are on GitHub/codeberg.

All my personal info and photos are on proton drive.

If Linux shits itself (and it does often) who cares. I can have it up and running again in a fresh install in ten minutes.

[–] possiblylinux127@lemmy.zip 47 points 19 hours ago

What's a backup?

[–] fossphi@lemm.ee 3 points 12 hours ago

I use restic, have also been looking at kopia and borg

[–] gerdesj@lemmy.ml 1 points 9 hours ago

You have loads of options but you need to also start from ... "what if". Work out how important your data really is. Take another look and ask the kids and others if they give a toss. You might find that no one cares about your photo collection in which case if your phone dies ... who cares? If you do care then sync them to a PC or laptop.

Perhaps take a look at this - https://www.veeam.com/products/free/linux.html its free for a few systems.

[–] astrsk@fedia.io 21 points 19 hours ago (3 children)

Borg backup is gold standard, with Vorta as a very nice GUI on machines that need it. Otherwise, all my other Linux machines are running in proxmox hypervisors and have container/snapshot/vm backups regularly through proxmox backup server to another machine. All the backup data is then replicated regularly, remotely via truenas scale replication tasks.

[–] NotAnArdvark@lemmy.ca 3 points 13 hours ago

Adding my "Me too" to Vorta/Borg. I use it with Borgbase, which I like because it's legitimately cheap and they support Borg development. As well, you can set Borg backups with Borgbase to "append only," which prevents ransomware or other unexpected "whoopsies" from wiping out your backup history.

I backup most of my computer every hour, but have pruning rules that make sure things don't get too out of hand. I have a second backup that backs everything up to my NAS (using Vorta, again). This is helpful for things like my downloads folder, virtual machines, or STEAM library - things I wouldn't want to backup over the network, but on occasion I do find myself going "whoops, I wanted that."

I also have Vorta working on my Mom's Macbook, then have Borgbase send me an email when there isn't any activity for longer than a couple of days. Once I got automatic pruning working right I never had to touch this again.

[–] GenderNeutralBro@lemmy.sdf.org 4 points 19 hours ago

Borg via Vorta handles the hard parts: encryption, compression, deduplication, and archiving. You can mount backup snapshots like drives, without needing to expand them. It splits archives into small chunks so you can easily upload them to your cloud service of choice.

load more comments (1 replies)
[–] faercol@lemmy.blahaj.zone 18 points 19 hours ago
[–] Xiisadaddy@lemmygrad.ml 4 points 14 hours ago

My laptop has a microsd card reader that when filled is almost flush so i just keep a micro sd card in there and have timeshift back up to it. Partitioned with full disk encryption so it cant just be stolen and scanned.

[–] potentiallynotfelix@lemmy.fish 1 points 10 hours ago

If I feel like it, I might use DD to clone my drive and put in on a hard drive. Usually I don't back up, though.

[–] somenonewho@feddit.org 3 points 13 hours ago

For files are in git (using stow to recreate) and my documents folder is syncing to nextcloud (selfhosted) and this also to my laptop. This is of course not a "Backup" per se more a "multiple copies" but it gets the job done and also firs my workflow. To be happy with that I want to set up an offsite backup of data from my server to a NAS in my parents place but right now that's just a to-do I haven't put any work in yet ;)

[–] earth_walker@lemmy.world 26 points 21 hours ago* (last edited 21 hours ago) (1 children)

I use Borg Backup, automated with a bash script that Borg provides. A cron job runs the script at the desired frequency. I keep backups on different computers, ideally I would recommend one copy in the cloud and one copy on a local machine. Borg compresses and encrypts its backups.

Edit: I migrated a server once using the backups from this system and it worked great.

[–] TheAgeOfSuperboredom@lemmy.ca 8 points 21 hours ago

Same.

I use Bortmatic to manage my repos and I pay a little bit to BorgBase for offsite backup of my important stuff.

[–] TimeSquirrel@kbin.melroy.org 12 points 18 hours ago (2 children)

I plug in an external drive every so often and drag and drop parts of my home dir into it like it's 1997. I'm not running a data center here. The boomer method is good enough and I don't do anything important enough to warrant going all out with professional snapshot based backup solutions and stuff. And I only save personal documents, media, and custom config files. Everything else is replaceable.

[–] lord_ryvan@ttrpg.network 1 points 5 hours ago

I do exactly this but with a little shell script that just has some rsync -av and mv -f calls instead of dragging and dropping.

[–] Frederic@beehaw.org 4 points 18 hours ago

yeah about the same, old coot here, I plug a USB3-SSD (encrypted with LUKS) and rsync from internal HD to this external HD. That's it.

[–] capital@lemmy.world 2 points 12 hours ago* (last edited 12 hours ago)

restic -> Wasabi, automated with shell script and cron. Uses an include list to tell it what paths to back up.

Script has Pushover credentials to send me backup alerts. Parses restic log to tell me how much was backed up, removed, success/failure of backup, and current repo size.

To be added: a periodic restore of a random file to have its hash compared to the current version of the file (will happen right after backup, unlikely to have changed in my workload), which will be subsequently deleted, and alert sent letting me know how the restore test went.

[–] MonkderVierte@lemmy.ml 3 points 14 hours ago* (last edited 14 hours ago)

Constant work in progress.

[–] krakenfury@lemmy.sdf.org 1 points 11 hours ago

I sync important files to s3 from a folder with awscli. Dot files and projects are in a private git repos. That's it.

If I maintained a server, I would do something more sophisticated, but installation is so dead simple these days that I could get a daily driver in working order very quickly.

[–] Joker@discuss.tchncs.de 4 points 16 hours ago

Vorta (borg) with backups sent to rsync.net. They run daily on all my machines.

[–] digdilem@lemmy.ml 4 points 16 hours ago

Scuse the cut and paste, but this is something I recently thought quite hard about and blogged, so stealing my own content:

What to back up? This is a core question to ask when you start planning. I think it’s quite simply answered by asking the secondary question: “Can I get the data again?” Don’t back up stuff you downloaded from the public internet unless it’s particularly rare. No TV, no Movies, no software installers. Don’t hoard data you can replace. Do back up stuff you’ve personally created and that doesn’t exist elsewhere, or stuff that would cause you a lot of effort or upset if it wasn’t available. Letters you’ve written, pictures you’ve taken, code you authored, configurations and systems that took you a lot of time to set up and fine tune.

If you want to be able to restore a full system, that’s something else and generally dealt best with imaging – I’m talking about individual file backups here!

Backup Scenario Multiple household computers. Home linux servers. Many services running natively and in docker. A couple of windows computers.

Daily backups Once a day, automate backups of your important files.

On my linux machines, that’s things like some directories like /etc, /root, /docker-data, some shared files.

On my windows machines, then that’s some mapping data, word documents, pictures, geocaching files, generated backups and so on.

You work out the files and get an idea of how much space you need to set aside.

Then, with automated methods, have these files copied or zipped up to a common directory on an always-available server. Let’s call that /backup.

These should be versioned, so that older ones get expired automatically. You can do that with bash scripts, or automated backup software (I use backup-manager for local machines, and backuppc or robocopy for windows ones)

How many copies you keep depends on your preferences – 3 is a sound number, but choose what you want and what disk space you have. More than 1 is a good idea since you may not notice the next day if something is missing or broken.

Monthly Backups – Make them Offline if possible

I puzzled a long time over the best way to do offline backups. For years I would manually copy the contents of /backup to large HDDs once a month. That took an hour or two for a few terabytes.

Now, I attach an external USB hard drive to my server, with a smart power socket controlled by Home Assistant.

This means it’s “cold storage”. The computer can’t access it unless the switch is turned on – something no ransomware knows about. But I can write a script that turns on the power, waits a minute for it to spin up, then mounts the drive and copies the data. When it’s finished, it’ll then unmount the drive and turn off the switch, and lastly, email me to say “Oi, change the drives, human”.

Once I get that email, I open my safe (fireproof and in a different physical building) and take out the oldest of three usb Caddies. Swap that with the one on the server and put that away. Classic Grandfather/Father/Son backups.

Once a year, I change the oldest of those caddies to “Annual backup, 2024” and buy a new one. That way no monthly drive will be older than three years, and I have a (probably still viable) backup by year.

BTW – I use USB3 HDD caddies (and do test for speed – they vary hugely) because I keep a fair bit of data. But you can also use one of the large capacity USB Thumbdrives or MicroSD cards for this. It doesn’t really matter how slowly it writes, since you’ll be asleep when it’s backing up. But you do really want it to be reasonably fast to read data from, and also large enough for your data – the above system gets considerably less simple if you need multiple disks.

Error Check: Of course with automated systems, you need additional automated systems to ensure they’re working! When you complete a backup, touch a file to give you a timestamp of when it was done – online and offline. I find using “tree” to catalogue the files is worthwhile too, so you know what’s on there.

Lastly – test your backups. Once or twice a year, pick a backup at random and ensure you can copy and unpack the files. Ensure they are what you expect and free from errors.

[–] PetteriPano@lemmy.world 4 points 16 hours ago

My desktop, laptop and homelab all synd my important stuff over syncthing. They all do btrfs snapshots three months back in case an oopsie would propagate.

The homelab additionally fetches deduplicated snapshots of my VPS weekly, before syncing all of the above to an encrypted hetzner storage for those burning-down-the-house events.

[–] clif@lemmy.world 1 points 12 hours ago* (last edited 12 hours ago)

Internal RAID1 as first line of defense. Rsync to external drives where at least one is always offsite as second. Rclone to cloud storage for my most important data as the third.

Backups 2 and 3 are manual but I have reminders set and do it about once a month. I don't accrue much new data that I can't easily replace so that's fine for me.

[–] 30p87@feddit.org 13 points 22 hours ago

I use rsync to incrementally back up / to a separate drive, as well as a drive on another device (my server), which then packs, compresses and encrypts the latest backup of all devices daily, and uploads them to Hetzner as well as GDrive.

[–] FrostyPolicy@suppo.fi 3 points 16 hours ago

Daily rsync to a local nas and weekly backups to offsite with pika-backup.

[–] aquafunk@lemmy.sdf.org 7 points 21 hours ago* (last edited 21 hours ago)

etckeeper, and borg/vorta for /home

I try to be good about everything being installed in packages, even if Im the one that made the package. that means I only have to worry about backing up my local package archive. but Ive never actualy recreated a personal system from a backup, and usually end up starting from a fresh install, slowly adding back things from the backup if I missed them. this tends to cut down on cruft and no longer needed hacks and fixes. also makes for a good way to be exposed to new paradigms (desktop environments, shells, etc)

something that helps is daily notes. one file for any day Im working on my system and want to remember what a custom file, confg edit, or downloaded/created package does and why. these get saved separately and I try to remember to grep them before asking the internet

i see the benefit to snapshots, but disk space is expensive, and Im (usually) careful (enough) not to lock myself out or prevent boots. anything catastophic I have to fix is usually seen as a fun, stressful learning experience! that rarely happens anymore, for better or for worse

[–] Kongar@lemmy.dbzer0.com 6 points 21 hours ago (1 children)

Synology NAS. I really love that thing. I use their synology drive software to backup the Linux home folder, as well as windows PCs, iPads, iPhones etc. I use their photos mobile software to automatically backup phone photos and videos. I also synchronize a few select folders between PCs so certain in-use files are always up to date. I set the NAS to keep 30 old versions of every file. This works great for my college kids - dad has a copy of everything in case they nuke a paper or something (which has happened).

I stopped cloning drives long ago. Now I just reinstall the os and packages. With Linux, this is honestly faster than deploying a backup - a single pacman command installs everything I want. Then I just log into things as I open them. Ya I might have to futz around with some settings or redownload some big games on steam - but the eye candy and games can wait - I can be productive pretty quickly after an install.

I DO use btrfs with automatic snapshots (snapper and btrfs assistant). This saves me from myself when I bork an update (which I’ve done more than once). If I make a mistake, I just rollback a snapshot, and try again without my stupid mistakes. This has saved my install 3 or 4 times now.

Lastly, I sneaker net an external hard drive to my office. On it is a manual backup of the NAS. I do this once per month. This protects from catastrophic failures like my house burning down. I might lose a month or so of pictures in the worst case scenario, but I still have my 25+ years of pictures of my kids, wedding videos, etc.

In the end, the only thing that really matters is not losing my lifetime of family pictures and the good memories they provoke.

load more comments (1 replies)
[–] LemmyBe@lemmy.world 3 points 18 hours ago* (last edited 18 hours ago)

I use Bluebuild to create a reproducible system, plus a post-install script to handle other post-install tasks such as setting up initial preferences.

Also Vorta to backup files and settings to external HD, plus OneDrive Linux client to sync files and settings to cloud.

[–] CrabAndBroom@lemmy.ml 5 points 20 hours ago

Currently I use Borg Backup with Vorta as a GUI. I don't really do anything automated/scheduled, I just back it up manually to an external SSD every few days or so. I pretty much do my whole /home folder, except for a couple of subfolders that aren't really necessary (and Videos, which I back up separately.)

I do eventually want to upgrade to a NAS, but I'm waiting until we move to start setting that up. Also I don't really have an off-site plan yet which I know is bad, but I need to figure that out.

[–] oscardejarjayes@hexbear.net 3 points 18 hours ago* (last edited 18 hours ago)

restic to a local server and to cloud storage. it varies by device, but usually just everything in /home/. The rest of the operating system should be reproducible, whether through images, ansible, nix, or guix, given the information in /home/.

scheduling is done through systemd, usually (or the non-systemd equivalent). I use BackBlaze now, but I switch around occasionally. restic has policy based snapshot removal, and a prune option.

[–] Vincent@feddit.nl 5 points 20 hours ago
[–] JustEnoughDucks@feddit.nl 2 points 17 hours ago* (last edited 16 hours ago)

321

Kopia backup to secondary HDD

  • Pictures (phone photos backed up to my server via immich)
  • workspace (git repos, ECAD, MCAD, firmware, etc...)
  • qmk layout
  • Documents
  • vim folder with bundles
  • ebooks

KDE vaults stores on secondary HDD

Soon I will set up kopia to also back up every via SSH to my server and then small size essentials and important docs via google drive

I need to set server cloud backups too, but haven't had the time...

load more comments
view more: next ›