Compare commits
34 Commits
ea3d2b76b5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ad26474a6 | |||
| 9d5303fdc6 | |||
| 707ebe3a62 | |||
| ba29fe637f | |||
| 73132456f3 | |||
| 1121ef6db8 | |||
| 80e47ee92d | |||
| 1e3b7b9e94 | |||
| c6e7e05eef | |||
| 74ded3ddbe | |||
| 36bf3c9ba5 | |||
| 153f1b0dcd | |||
| 3ccf6c1758 | |||
| aed2e11a47 | |||
| 9c2a255e1c | |||
| 77016eefaa | |||
| 4478fc74c8 | |||
| db4006a820 | |||
| 69aa1b6903 | |||
| f03af21605 | |||
| fe910e5f79 | |||
| 6b1790171d | |||
| 2d9f26a558 | |||
| 97fb7da9b3 | |||
| f03573d275 | |||
| 8719bfbe27 | |||
| ed6614c4b1 | |||
| f08ba95750 | |||
| d81683b431 | |||
| 3bd1c3f9bd | |||
| 42782597cd | |||
| 4fedc39d1a | |||
| f4e42a53be | |||
| f978c47939 |
32
.gitea/workflows/pingflow.yaml
Normal file
32
.gitea/workflows/pingflow.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Ansible Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python
|
||||
#uses: actions/setup-python@v4
|
||||
run: |
|
||||
apt -y update
|
||||
apt -y install python3 python3-pip
|
||||
|
||||
- name: Install Ansible
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
pip install ansible
|
||||
|
||||
- name: Set up SSH
|
||||
uses: webfactory/ssh-agent@v0.5.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Run Ansible Playbook
|
||||
run: |
|
||||
ansible-playbook -i inventory.yml ping.yaml -vv
|
||||
179
Kumonoboru
179
Kumonoboru
@@ -1,179 +0,0 @@
|
||||
#!/bin/bash
|
||||
##Simple script to run Restic backups
|
||||
source /root/.bash_profile
|
||||
source /home/shmick/Scripts/Okiru
|
||||
source /etc/environment
|
||||
export HOME=/root/
|
||||
arg0=$(basename "$0")
|
||||
#Show help if arguments are misused
|
||||
usage()
|
||||
{
|
||||
exec 1>2 # Send standard output to standard error
|
||||
help
|
||||
exit 1
|
||||
}
|
||||
|
||||
flag_error()
|
||||
{
|
||||
echo -e "$arg0: $*." >&2
|
||||
help
|
||||
exit 1
|
||||
}
|
||||
|
||||
help()
|
||||
{
|
||||
echo "$arg0 - Back up important location to the B2 cloud using Restic."
|
||||
echo " {-c|--clean} -- Force prune of the remote repositories"
|
||||
echo " {-r|--repository} repository -- Only backup the specified repository."
|
||||
echo " {-l|--limit} #[Kbps] -- Limit upload & download speed"
|
||||
echo " {-h|--help} -- Print this help message and exit"
|
||||
echo "Available repositories:"
|
||||
echo "Gerbil-TK Photos (path: /var/Red-Vol/Media/Pictures)"
|
||||
echo "Pukeko-XYZ-Containers Containers (path: /var/Red-Vol/Media/Containers)"
|
||||
echo "Pukeko-XYZ-Cloud Data from all devices (path: /var/Red-Vol/Media/Cloud/Syncthing)"
|
||||
exit 0
|
||||
}
|
||||
#Pass arguments to the script
|
||||
flags()
|
||||
{
|
||||
#This is utterly useless
|
||||
if [[ $# == "0" ]]; then
|
||||
:
|
||||
fi
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
(-c|--clean)
|
||||
debug "Cleaning will take place per request."
|
||||
export CLEAN="1"
|
||||
shift;;
|
||||
(-r|--repository)
|
||||
shift
|
||||
export REPOSITORY="$1"
|
||||
debug "Only repository $1 will be processed per request."
|
||||
shift;;
|
||||
(-l|--limit)
|
||||
shift
|
||||
export BWLIMIT="$1"
|
||||
debug "Bandwidth will be limited to $BWLIMIT Kbps per request."
|
||||
shift;;
|
||||
(-h|--help)
|
||||
help;;
|
||||
(*) help;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
flags "$@"
|
||||
logging Kumonoboru
|
||||
#Defaults
|
||||
if [[ -z $BWLIMIT ]]; then
|
||||
export BWLIMIT="0"
|
||||
fi
|
||||
#Safety function; accepts repository to check
|
||||
safety(){
|
||||
REPOSITORY="$1"
|
||||
info "Checking if repository $REPOSITORY is in use..."
|
||||
#Check no other Restic process is using this repository; Free unnecessary locks, if present
|
||||
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
|
||||
warn "Repository $REPOSITORY is in use - ignoring"
|
||||
return 1
|
||||
# ^ If there's a restic process holding the repository, leave it alone.
|
||||
else
|
||||
info "Repository $REPOSITORY is not in use - unlocking"
|
||||
restic -r b2:$REPOSITORY unlock
|
||||
# ^ If a lock exists but no process, the repository is safe and should be unlocked.
|
||||
fi
|
||||
}
|
||||
#Backup function; accepts repository and path to backup
|
||||
backup(){
|
||||
REPOSITORY="$1"
|
||||
REPOSITORY_PATH="$2"
|
||||
if safety "$REPOSITORY"; then
|
||||
#Run the backup
|
||||
info "Backing up repository $REPOSITORY"
|
||||
if restic -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH" --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
||||
ok "Path $REPOSITORY_PATH completed upload to $REPOSITORY."
|
||||
check "$REPOSITORY"
|
||||
else
|
||||
error "Repository $REPOSTIORY failed to upload path $REPOSITORY_PATH!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
check(){
|
||||
REPOSITORY="$1"
|
||||
PRUNE="$2"
|
||||
debug "Working on Repostory $1 with prune option $2"
|
||||
## ^ This variable will have value if repo is already clean, indicating
|
||||
#+ This is a post backup check.
|
||||
if [[ -n $PRUNE ]]; then
|
||||
warn "This repository has been cleaned already; will not clean again."
|
||||
fi
|
||||
if safety "$REPOSITORY"; then
|
||||
info "Checking repository $REPOSITORY"
|
||||
if restic -r b2:"$REPOSITORY" check --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
||||
ok "Repository $REPOSITORY passed integrity check!"
|
||||
info "Current snapshots:"
|
||||
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
|
||||
else
|
||||
error "Repository $REPOSITORY failed integrity check!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
clean(){
|
||||
REPOSITORY="$1"
|
||||
if safety "$REPOSITORY"; then
|
||||
info "Cleaning repository $REPOSITORY"
|
||||
if restic -r b2:$REPOSITORY forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
||||
ok "Repository $REPOSITORY is trim!"
|
||||
debug "Running post clean check..."
|
||||
check "$REPOSITORY" "1"
|
||||
# Marks repository as cleaned already ^ so it won't passed to this function again.
|
||||
else
|
||||
error "Repository $REPOSITORY failed to prune!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
#If a specific repository was requested, back it up; otherwise, back them all up.
|
||||
if [[ -n $REPOSITORY ]] && [[ -z $CLEAN ]]; then
|
||||
case "$REPOSITORY" in
|
||||
(Gerbil-TK)
|
||||
backup Gerbil-TK /var/Red-Vol/Media/Pictures/
|
||||
;;
|
||||
(Pukeko-XYZ-Containers)
|
||||
backup Pukeko-XYZ-Containers /var/Red-Vol/Media/Containers
|
||||
;;
|
||||
(Pukeko-XYZ-Cloud)
|
||||
backup Pukeko-XYZ-Cloud /var/Red-Vol/Media/Cloud/Syncthing
|
||||
;;
|
||||
(*)
|
||||
help;;
|
||||
esac
|
||||
#If cleaning was not forced, backup the repositories
|
||||
elif [[ -z $CLEAN ]]; then
|
||||
backup Gerbil-TK /var/Red-Vol/Media/Pictures/
|
||||
backup Pukeko-XYZ-Containers /var/Red-Vol/Media/Containers
|
||||
backup Pukeko-XYZ-Cloud /var/Red-Vol/Media/Cloud/Syncthing
|
||||
#If a specific repository was requested to be cleaned, clean it
|
||||
elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then
|
||||
case "$REPOSITORY" in
|
||||
(Gerbil-TK)
|
||||
clean Gerbil-TK
|
||||
;;
|
||||
(Pukeko-XYZ-Containers)
|
||||
clean Pukeko-XYZ-Containers
|
||||
;;
|
||||
(Pukeko-XYZ-Cloud)
|
||||
clean Pukeko-XYZ-Cloud
|
||||
;;
|
||||
(*)
|
||||
help;;
|
||||
esac
|
||||
#If cleaning was forced and no repository specified, clean all repositories
|
||||
elif [[ -n $CLEAN ]] || [[ $(date +%a) == "Friday" ]]; then
|
||||
clean Gerbil-TK
|
||||
clean Pukeko-XYZ-Containers
|
||||
clean Pukeko-XYZ-Cloud
|
||||
fi
|
||||
#Wrap up this run's log and report nicely
|
||||
end_logging
|
||||
exit 0
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
#Script to backup all important environment files
|
||||
source /etc/environment
|
||||
source $SCRIPTS/Okiru
|
||||
source /home/shmick/Scripts/Okiru
|
||||
logging "ConfigBackup"
|
||||
export CONF_DIR="/home/shmick/Config"
|
||||
if [[ ! -d $CONF_DIR ]]; then
|
||||
@@ -48,10 +47,10 @@ conf_sync /etc/profile
|
||||
for conf in $(ls /etc/snapper/configs/* 2> /dev/null); do
|
||||
conf_sync $conf
|
||||
done
|
||||
for conf in $(ls /etc/systemd/system/murchison*); do
|
||||
for conf in $(ls /etc/systemd/system/Murchison*); do
|
||||
conf_sync $conf
|
||||
done
|
||||
for conf in $(ls /etc/systemd/system/kumonoboru*); do
|
||||
for conf in $(ls /etc/systemd/system/Kumonoboru*); do
|
||||
conf_sync $conf
|
||||
done
|
||||
#Fix permissions
|
||||
|
||||
66
Okiru
66
Okiru
@@ -31,6 +31,9 @@ WHITE='\033[0;37m'
|
||||
GRAY='\033[1;37m'
|
||||
STOP="\e[0m"
|
||||
|
||||
#If passed from calling script, run in verbose mode (enables debug logging level)
|
||||
VERBOSE="$VERBOSE"
|
||||
|
||||
|
||||
#If a function calls 'logging' for a log, it will create a log file; otherwise, keep the
|
||||
#+variable empty thus printing only to terminal
|
||||
@@ -76,37 +79,69 @@ logging () {
|
||||
printf "Logging is ${RED}disabled${STOP}; No log file will be generated.\n"
|
||||
fi
|
||||
}
|
||||
#If VERBOSE mode is enabled, print debug messages
|
||||
if [[ -n $VERBOSE ]]; then
|
||||
#Debugging level logging; can be toggled via a switch
|
||||
debug () {
|
||||
printf "${BLUE}[DEBUG]: $1${STOP}\n"
|
||||
if [[ -z $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${BLUE}[DEBUG]: %s${STOP}\n" "$1"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date | awk '{print $4}') [DEBUG]: $1" >> $LOG
|
||||
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
|
||||
fi
|
||||
elif [[ -n $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${BLUE}[DEBUG]: %s${STOP} ${LIGHT_BLUE}%s${STOP}\n" "$1" "$2"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
|
||||
fi
|
||||
|
||||
fi
|
||||
}
|
||||
#Otherwise, ignore debug calls;
|
||||
else
|
||||
debug () {
|
||||
:
|
||||
}
|
||||
fi
|
||||
#Information level logging;
|
||||
info () {
|
||||
printf "${CYAN}[INFO]:${STOP} $1\n"
|
||||
if [[ -z $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${CYAN}[INFO]:${STOP} %s\n" "$1"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date | awk '{print $4}') [INFO]: $1" >> $LOG
|
||||
echo -e "$(date +"%T:%N") [INFO]: $1" >> $LOG
|
||||
fi
|
||||
elif [[ -n $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${CYAN}[INFO]:${STOP} %s ${LIGHT_CYAN}%s${STOP}\n" "$1" "$2"
|
||||
if [[ -f $LOG ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${CYAN}[INFO]:${STOP} %s ${LIGHT_CYAN}%s${STOP}\n" "$1" "$2" >> $LOG
|
||||
fi
|
||||
fi
|
||||
}
|
||||
#Warning level logging;
|
||||
warn () {
|
||||
printf "${YELLOW}[WARNING]:${STOP} $1\n"
|
||||
if [[ -z $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${ORANGE}[WARNING]:${STOP} %s\n" "$1"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date | awk '{print $4}') [WARN]: $1" >> $LOG
|
||||
echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG
|
||||
fi
|
||||
elif [[ -n $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${ORANGE}[WARNING]:${STOP} %s ${YELLOW}%s${STOP}\n" "$1" "$2"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG
|
||||
fi
|
||||
fi
|
||||
}
|
||||
#Error logging function; Errors are added to an array and a report file.
|
||||
error () {
|
||||
echo $1 1>&2
|
||||
# ` ^ Output error message to stderr
|
||||
printf "${RED}[ERROR]: $1${STOP}\n"
|
||||
if [[ -z $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${RED}[ERROR]: %s${STOP}\n" "$1"
|
||||
# ^ Print it to the screen
|
||||
elif [[ -n $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${RED}[ERROR]: %s${STOP}${LIGHT_RED} %s${STOP}\n" "$1"
|
||||
fi
|
||||
errors+=("$1")
|
||||
# ^ And add to errors array
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date | awk '{print $4}') [ERROR]: $1" >> $LOG
|
||||
echo -e "$(date +"%T:%N") [ERROR]: $1" >> $LOG
|
||||
# ^ Log it with its' time and date
|
||||
fi
|
||||
if [[ -f $REPORT ]]; then
|
||||
@@ -116,9 +151,16 @@ error () {
|
||||
return 1
|
||||
}
|
||||
ok () {
|
||||
printf "${GREEN}[SUCCESS]: $1${STOP}\n"
|
||||
if [[ -z $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${GREEN}[SUCCESS]: %s${STOP}\n" "$1"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date | awk '{print $4}') [SUCCESS]: $1" >> $LOG
|
||||
echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG
|
||||
fi
|
||||
elif [[ -n $2 ]]; then
|
||||
printf "${PURPLE}$(date +"%T:%N")${STOP} ${GREEN}[SUCCESS]:${LIGHT_GREEN} %s${STOP}${GREEN} %s${STOP}\n" "$1" "$2"
|
||||
if [[ -f $LOG ]]; then
|
||||
echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
5
inventory.yml
Normal file
5
inventory.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
all:
|
||||
hosts:
|
||||
takahe:
|
||||
ansible_host: 192.168.0.66
|
||||
ansible_user: shmick
|
||||
Reference in New Issue
Block a user