feat: git weekly backups
This commit is contained in:
parent
a2e0884383
commit
80dbae3b8a
2 changed files with 57 additions and 16 deletions
|
|
@ -1,19 +1,45 @@
|
||||||
#+OPTIONS: toc:nil
|
#+OPTIONS: toc:nil
|
||||||
|
|
||||||
* ROOT SERVICES
|
* INIT SYSTEM
|
||||||
|
|
||||||
|
** ROOT SERVICES (Currently none!)
|
||||||
=<service>.sh= to be symlinked to =/etc/init.d/podman-containers=
|
=<service>.sh= to be symlinked to =/etc/init.d/podman-containers=
|
||||||
* USER SERVICES AND RUNLEVELS
|
** USER SERVICES AND RUNLEVELS
|
||||||
=.config= folder to be symlinked to =~=
|
=.config= folder to be symlinked to =~=
|
||||||
* XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN
|
** * XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN
|
||||||
=.profile= to be symlinked to =/home/$USER/.profile=
|
=.profile= to be symlinked to =/home/$USER/.profile=
|
||||||
|
|
||||||
* RUN USERS SERVICES ON BOOT
|
** RUN USERS SERVICES ON BOOT
|
||||||
Symlink =/etc/init.d/user= to =/etc/init.d/user.$usernames=. After add, add the latter service with =rc-update= as root.
|
Symlink =/etc/init.d/user= to =/etc/init.d/user.$usernames=. After add, add the latter service with =rc-update= as root.
|
||||||
|
|
||||||
* IF <USER> HAS PASSWORD
|
** IF <USER> HAS PASSWORD
|
||||||
Add the following to a new file in =/etc/doas.d/=:
|
Add the following to a new file in =/etc/doas.d/=:
|
||||||
|
|
||||||
#+begin_src shell
|
#+begin_src shell
|
||||||
permit nopass <user> as <user>
|
permit nopass <user> as <user>
|
||||||
permit nopass root as <user>
|
permit nopass root as <user>
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
* Timed cron jobs
|
||||||
|
|
||||||
|
First, swap built-in =crond= for =dcron=. We need to swap cron binaries since we would have to give setgid capabilites to the whole Busybox binary to use the included cron binary, for which we also need to install =libcap=:
|
||||||
|
|
||||||
|
#+begin_src shell
|
||||||
|
# apk add dcron libcap
|
||||||
|
,** if crond is set up, remember to stop and delete it before continuing!
|
||||||
|
# rc-service dcron start
|
||||||
|
# rc-update add dcron
|
||||||
|
# setcap cap_setgid=ep /usr/sbin/crond
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
After this, remember to add =root= and =$USER= to the =cron= group!
|
||||||
|
|
||||||
|
We now set up =$USER='s crontab as such:
|
||||||
|
|
||||||
|
#+begin_src shell
|
||||||
|
#crontab -u $USER -e
|
||||||
|
|
||||||
|
@weekly ID=git-back.weekly /home/$user/pihanepi/orchestrating/cronjobs/forgejo-clone/forgejo-clone.sh
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Finally, check =/var/log/messages= to confirm everything ran successfully.
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,15 @@ echo $repo_urls
|
||||||
echo "----\n"
|
echo "----\n"
|
||||||
|
|
||||||
#Cloning each repo to destdir
|
#Cloning each repo to destdir
|
||||||
i=0;
|
repo_idx=0;
|
||||||
finished=false;
|
repo_finished=false;
|
||||||
while ! $finished
|
while ! $repo_finished
|
||||||
do
|
do
|
||||||
i=$(($i+1));
|
repo_idx=$(($repo_idx+1));
|
||||||
repo=$(awk "{print \$$i}" <(echo $repo_urls))
|
repo=$(awk "{print \$$repo_idx}" <(echo $repo_urls))
|
||||||
if [ "$repo" = "" ]
|
if [ "$repo" = "" ]
|
||||||
then
|
then
|
||||||
finished=true
|
repo_finished=true
|
||||||
else
|
else
|
||||||
#Retrieve repo name for folder
|
#Retrieve repo name for folder
|
||||||
repo_name="$(awk -F/ '{print $5}' <(echo $repo))"
|
repo_name="$(awk -F/ '{print $5}' <(echo $repo))"
|
||||||
|
|
@ -42,16 +42,31 @@ do
|
||||||
#Remove quotes from user_username
|
#Remove quotes from user_username
|
||||||
username=${user_username%\"}
|
username=${user_username%\"}
|
||||||
username=${username#\"}
|
username=${username#\"}
|
||||||
#Clone repo
|
#Clone or rebase repo
|
||||||
#TODO: what do if repo already exists? if it!
|
|
||||||
if [ -e "$REPO_DIR$repo_name" ]
|
if [ -e "$REPO_DIR$repo_name" ]
|
||||||
then
|
then
|
||||||
echo "REPO: $repo_name"
|
echo "REPO: $repo_name"
|
||||||
git -C "$REPO_DIR$repo_name" fetch --all
|
git -C "$REPO_DIR$repo_name" fetch -t --all
|
||||||
#git -C "$REPO_DIR$repo_name" rebase --update-refs
|
branch="$(git -C "$REPO_DIR$repo_name" branch | awk '{print $2}')"
|
||||||
|
git -C "$REPO_DIR$repo_name" rebase $branch --onto origin/$branch
|
||||||
else
|
else
|
||||||
git clone https://$user_username:$AUTH_TOKEN@$GIT_DOMAIN/$username/$repo_name /home/$USER/pihanepi/datamount/gitbackup/$repo_name --recurse-submodules
|
git clone https://$user_username:$AUTH_TOKEN@$GIT_DOMAIN/$username/$repo_name /home/$USER/pihanepi/datamount/gitbackup/$repo_name --recurse-submodules
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#NOTE: Cool git formatting and same loop to operate on all remote branches
|
||||||
|
#branches="$(git -C $REPO_DIR$repo_name branch -r --format='%(refname:short)' | awk -F/ '{if ($2) print $2;}')"
|
||||||
|
#branch_idx=0;
|
||||||
|
#branch_finished=false;
|
||||||
|
#while ! $branch_finished
|
||||||
|
#do
|
||||||
|
# branch_idx=$(($branch_idx+1));
|
||||||
|
# branch=$(awk "{print \$$branch_idx}" <(echo $branches))
|
||||||
|
# if [ "$branch" = "" ]
|
||||||
|
# then
|
||||||
|
# branch_finished=true
|
||||||
|
# else
|
||||||
|
# git -C "$REPO_DIR$repo_name" rebase $branch --onto origin/$branch
|
||||||
|
# fi
|
||||||
|
#done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue