added bin and wrote backup script, restore isnt finished

This commit is contained in:
2022-01-14 14:19:09 -05:00
parent e15a76ec40
commit d6c388bfb5
15 changed files with 378 additions and 0 deletions

35
backup Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
declare -A to_copy to_rsync
repo="$(pwd)"
# files to copy
to_copy["${HOME}/.bashrc"]='shell/bashrc'
# directories to copy
to_rsync["${HOME}/.config/aliases"]='aliases'
# directories to copy
to_rsync["${HOME}/bin"]='bin'
for src in "${!to_copy[@]}"; do
dst="${to_copy[$src]}"
dir="$(dirname "$dst")"
file="$(basename "$dst")"
if [[ ! -d "${repo}/${dir}" ]]; then
mkdir -p "${repo}/${dir}"
fi
rsync -a "$src" "${repo}/${dir}/${file}"
if [[ $? != 0 ]]; then
printf 'Copying "%s" to "%s" had an error.\n' "$src" "$dst" >&2
fi
done
for src in "${!to_rsync[@]}"; do
dst="${to_rsync[$src]}"
if [[ ! -d "$src" ]]; then
printf '"%s" does not exist. Can not copy.\n' "$src" >&2
else
(cd "$src" && rsync -a * "${repo}/${dst}/")
fi
done