feat: git weekly backups
This commit is contained in:
parent
a2e0884383
commit
bd144370ca
2 changed files with 54 additions and 16 deletions
|
|
@ -1,19 +1,42 @@
|
|||
#+OPTIONS: toc:nil
|
||||
|
||||
* ROOT SERVICES
|
||||
* INIT SYSTEM
|
||||
|
||||
** ROOT SERVICES (Currently none!)
|
||||
=<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 =~=
|
||||
* XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN
|
||||
** * XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN
|
||||
=.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.
|
||||
|
||||
* IF <USER> HAS PASSWORD
|
||||
** IF <USER> HAS PASSWORD
|
||||
Add the following to a new file in =/etc/doas.d/=:
|
||||
|
||||
#+begin_src shell
|
||||
permit nopass <user> as <user>
|
||||
permit nopass root as <user>
|
||||
#+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. We also need to install =libcap= to set capabilities:
|
||||
|
||||
#+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
|
||||
#+end_src
|
||||
|
||||
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"
|
||||
|
||||
#Cloning each repo to destdir
|
||||
i=0;
|
||||
finished=false;
|
||||
while ! $finished
|
||||
repo_idx=0;
|
||||
repo_finished=false;
|
||||
while ! $repo_finished
|
||||
do
|
||||
i=$(($i+1));
|
||||
repo=$(awk "{print \$$i}" <(echo $repo_urls))
|
||||
repo_idx=$(($repo_idx+1));
|
||||
repo=$(awk "{print \$$repo_idx}" <(echo $repo_urls))
|
||||
if [ "$repo" = "" ]
|
||||
then
|
||||
finished=true
|
||||
repo_finished=true
|
||||
else
|
||||
#Retrieve repo name for folder
|
||||
repo_name="$(awk -F/ '{print $5}' <(echo $repo))"
|
||||
|
|
@ -42,16 +42,31 @@ do
|
|||
#Remove quotes from user_username
|
||||
username=${user_username%\"}
|
||||
username=${username#\"}
|
||||
#Clone repo
|
||||
#TODO: what do if repo already exists? if it!
|
||||
#Clone or rebase repo
|
||||
if [ -e "$REPO_DIR$repo_name" ]
|
||||
then
|
||||
echo "REPO: $repo_name"
|
||||
git -C "$REPO_DIR$repo_name" fetch --all
|
||||
#git -C "$REPO_DIR$repo_name" rebase --update-refs
|
||||
git -C "$REPO_DIR$repo_name" fetch -t --all
|
||||
branch="$(git -C "$REPO_DIR$repo_name" branch | awk '{print $2}')"
|
||||
git -C "$REPO_DIR$repo_name" rebase $branch --onto origin/$branch
|
||||
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
|
||||
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