Skip to content

Instantly share code, notes, and snippets.

@Jipok
Created March 7, 2025 09:45
Show Gist options
  • Save Jipok/35092967e768a4e120c490b648ace0f7 to your computer and use it in GitHub Desktop.
Save Jipok/35092967e768a4e120c490b648ace0f7 to your computer and use it in GitHub Desktop.
Backup HOME with restic, exclude trash, caches and other useless data
#!/usr/bin/env bash
echo -e "\033[0;32mПароль в keepass под именем restic\033[0m"
# 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 -r sftp:local:/mainpool/backup/void-pc backup "$HOME")
for ex in "${excludes[@]}"; do
cmd+=(--exclude "$ex")
done
# Execute the command
"${cmd[@]}"
# Восстанавить ~/bin так:
# restic -r sftp:local:/mainpool/backup/void-pc restore latest --target / --include /home/kiv/bin
# Если в latest нету, то можно указать другой снапшот взяв ID из:
# restic -r sftp:local:/mainpool/backup/void-pc snapshots
# Посмотреть контент:
# restic ls latest -r sftp:local:/mainpool/backup/void-pc | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment