added bin and wrote backup script, restore isnt finished
This commit is contained in:
35
backup
Executable file
35
backup
Executable 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
|
Reference in New Issue
Block a user