mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 19:05:17 +00:00
flake parts
This commit is contained in:
parent
6dfef30594
commit
9a13c35acd
7 changed files with 144 additions and 90 deletions
25
scripts/home-manager-backup.sh
Normal file
25
scripts/home-manager-backup.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
target_path="${1:?expected target path}"
|
||||
base_backup="${target_path}.hm-bak"
|
||||
|
||||
if [[ ! -e "$base_backup" ]]; then
|
||||
mv "$target_path" "$base_backup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
timestamp="$(date +%Y%m%d-%H%M%S)"
|
||||
backup_path="${base_backup}.${timestamp}"
|
||||
suffix=0
|
||||
|
||||
while [[ -e "$backup_path" ]]; do
|
||||
suffix=$((suffix + 1))
|
||||
backup_path="${base_backup}.${timestamp}.${suffix}"
|
||||
done
|
||||
|
||||
mv "$target_path" "$backup_path"
|
||||
Loading…
Add table
Add a link
Reference in a new issue