-
-
Save maurerle/43deec998dbb521632218d82c81fb829 to your computer and use it in GitHub Desktop.
Backup HOME with restic, exclude trash, caches and other useless data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# SET ENV VARIABLES FOR YOUR USE CASE | |
# export RESTIC_PASSWORD= | |
# export RESTIC_REPOSITORY=sftp:host:/mnt/folder | |
# Each element is the exclusion path | |
excludes=( | |
"$HOME/.local" # Local configuration and application files | |
"$HOME/.cache" # Temporary cache files | |
"$HOME/Downloads" # Downloads folder | |
"$HOME/go" # Go workspace directory | |
"$HOME/Android" # Android project directories and temporary files | |
"$HOME/.android" # Android system settings and cache directories | |
"$HOME/.vmodules" # V lang modules directory | |
"$HOME/.var" # Variable data directory | |
"$HOME/.arduino*" # Arduino tool caches and temporary files | |
"$HOME/.gradle" # Gradle caches and build data | |
"$HOME/.java" # Local Java build artifacts | |
"$HOME/.thumbnails" # Auto-generated thumbnail caches | |
"$HOME/.pkg-cache" # Package tool cache (node.js pkg) content | |
'**/node_modules' # Node.js dependencies directory | |
'**/__pycache__' # Python __pycache__ directories | |
'**/.venv' # Python virtual environment directories | |
'**/venv' # Python virtual environment directories | |
"$HOME/.rbenv" # Ruby version manager directory | |
"$HOME/.gem" # Ruby gems storage | |
"$HOME/.cargo" # Rust toolchain cache directory | |
"$HOME/.rustup" # Rustup configuration and cache | |
"$HOME/.m2" # Maven dependency cache for Java | |
"$HOME/.ivy2" # Ivy dependency cache for Java projects | |
"$HOME/.composer" # PHP Composer cache directory | |
"$HOME/.stack" # Haskell Stack working directories | |
"$HOME/.cabal" # Haskell Cabal build artifacts and caches | |
"$HOME/perl5" # Local Perl modules directory | |
"$HOME/.cpanm" # CPAN Minus cache for Perl | |
"$HOME/.luarocks" # LuaRocks cache and modules for lua | |
"$HOME/.mix" # Mix build tool cache for Elixir | |
"$HOME/.sbt" # SBT cache directory for Scala and Java | |
"$HOME/.npm" # Node package manager (npm) cache | |
"$HOME/.bundle" # Bundler cache for Ruby packages | |
"$HOME/.nimble" # Nimble modules directory for Nim | |
'**/nimcache' # Nim compiler cache directories | |
'**/zig-cache' # Zig build cache directories | |
'**/zig-out' # Zig output directories | |
"$HOME/.pub-cache" # Dart/Flutter pub cache | |
"$HOME/.opam" # opam packages for OCaml | |
"$HOME/.coursier" # Coursier cache for Scala/Java | |
"$HOME/.nuget" # .NET NuGet packages cache | |
"$HOME/.dub" # DUB cache directory for D language | |
'**/nohup.out' # All nohup output files in subdirectories | |
"$HOME/.config/Code/Cache*" # VSCode cached data | |
"$HOME/.config/VSCodium/Cache*" # VSCode cached data | |
"$HOME/.config/Code - OSS/Cache*" # VSCode cached data | |
) | |
# Build the command with the excludes from the array | |
cmd=(restic backup "$HOME") | |
for ex in "${excludes[@]}"; do | |
cmd+=(--exclude "$ex") | |
done | |
# Execute the command | |
"${cmd[@]}" | |
# To recover ~/bin: | |
# restic restore latest --target / --include /home/maurer/bin | |
# select a different snapshot | |
# restic snapshots | |
# show existing snapshots | |
# restic ls latest | less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment