Compare commits
5 Commits
521d08969b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b890529d1 | |||
| 63f7d3e3bf | |||
| 0d2c7660fb | |||
| 804bf3e964 | |||
| aa74cf42f8 |
79
README.md
79
README.md
@@ -1,2 +1,81 @@
|
|||||||
# PBSupper
|
# PBSupper
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This program/container automatically powers on a remote server via 623/UDP to iDRAC, and likely other BMCs, connects to Proxmox Backup Server via SSH, so 22/TCP but this can be customized, creates and runs a sync-job, then shuts down PBS.
|
||||||
|
|
||||||
|
|
||||||
|
## Why?
|
||||||
|
|
||||||
|
I wanted to automate waking up my server, running a sync-job and shuting down said server. iDRAC6/7 doesn't have that option so I've built one.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Configurations
|
||||||
|
|
||||||
|
Here is a description of the most necessary and all the other environment variables
|
||||||
|
|
||||||
|
|
||||||
|
### Necessary envs
|
||||||
|
|
||||||
|
#### BMC envs
|
||||||
|
|
||||||
|
* IDRAC -- IP address of the remote BMC **(Default: None)**
|
||||||
|
* IDRAC_USR -- Username of the remote BMC. This user needs to have permission to power on/off the server as well as check the power status **(Default: None)**
|
||||||
|
* IDRAC_PWD -- Password of the IDRAC_USR user **(Default: None)**
|
||||||
|
|
||||||
|
#### Remote Server envs
|
||||||
|
|
||||||
|
* HOST -- IP address, or FQDN, of Proxmox Backup Server. It needs to listen for SSH connections **(Default: None)**
|
||||||
|
* HOST_USR -- Username of the user on Proxmox Backup Server **(Default: root)**
|
||||||
|
* HOST_USR_PWD -- Password for the username specified in **HOST_USR** **(Default: None)**
|
||||||
|
|
||||||
|
If you want to use SSH-keys, use the following environment variables and leave **HOST_USR_PWD** empty
|
||||||
|
|
||||||
|
* HOST_USR_SSHKEY -- Private ssh-key that will be user to connect to PBS. Leave empty if using username+password **(Default: None)**
|
||||||
|
* HOST_USR_SSHKEY_PASS -- Passphrase for the ssh-key. Leave empty if key is passwordless **(Default: None)**
|
||||||
|
|
||||||
|
|
||||||
|
#### PBS envs
|
||||||
|
|
||||||
|
* LOCAL_DATASTORE -- Name of the datastore on the PBS that is passed in **HOST** variable **(Default: None)**
|
||||||
|
* REMOTE_DATASTORE -- Name of the datastore that the local datastore will sync to/from **(Default: None)**
|
||||||
|
* REMOTE_PBS -- IP address, or FQDN, of the remote PBS that the local PBS will sync to/from **(Default: None)**
|
||||||
|
|
||||||
|
|
||||||
|
#### Container-specific envs
|
||||||
|
|
||||||
|
* RUN_SCHEDULE -- At what time should the server be woken up. Written in Cron notation **(Default: "45 17 * * 5")**
|
||||||
|
* RUN_SCHEDULE_TZ -- Timezone in which container is. Set to your local timezone as otherwise the wake-up time might be inaccurate. **(Default: "Europe/Stockholm")**
|
||||||
|
|
||||||
|
|
||||||
|
### Other environment variables
|
||||||
|
|
||||||
|
Here are the other environment variables that can be set
|
||||||
|
|
||||||
|
|
||||||
|
* HOST_SSH_PORT -- SSH port at which PBS is listening on **(Default: 22)**
|
||||||
|
|
||||||
|
* SYNC_DIR -- Direction of the sync-job. **(Default: push)**
|
||||||
|
* PBS_RATE_OUT -- Speed at which sync is *sent*. Reffer to [PBS documentation](https://pbs.proxmox.com/docs/managing-remotes.html#bandwidth-limit) **(Default: None)**
|
||||||
|
* PBS_RATE_IN -- Speed at which sync is *received*. Reffer to [PBS documentation](https://pbs.proxmox.com/docs/managing-remotes.html#bandwidth-limit) **(Default: None)**
|
||||||
|
* PBS_TASK_LIMIT -- How many tasks should be analyzed. Best to leave it at default **(Default: 50)**
|
||||||
|
* PBS_MAX_RUNTIME_MIN -- Max time which PBS might run after the sync-job. Usually it is caused by Verification jobs or Garbage collection jobs. If a *aptupdate*, *reader* or other tasks are running, then MAX_RUNTIME might be longer as these tasks are critical. **(Default: 180)**
|
||||||
|
* PBS_MAX_SHUT_MIN -- Max time which PBS has for a safe shutdown. This variable is used after a *shutdown* command is sent to PBS server. **(Default: 10)**
|
||||||
|
* AUTO_ADD_NAME -- This is a name that is set as sync-job id. **(Default: "autoBackupScript_one-shot")**
|
||||||
|
|
||||||
|
|
||||||
|
* RUN_ONE_SHOT -- If the script should only be ran once. Do not set/use unless you have specific usecase. **(Default: False)**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
 
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
@@ -1,18 +1,18 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
# sudo crontab -e
|
|
||||||
# 0 2 * * * cd /path/to/docker-compose && /usr/bin/docker compose up -d >> /var/log/pbsupper-docker-compose.log 2>&1
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
pbsupper-1:
|
pbsupper-1:
|
||||||
container_name: pbsupper
|
container_name: pbsupper
|
||||||
user: 1600:1600
|
user: 1600:1600
|
||||||
image: tea.shupogaki.org/yuruc3/pbsupper:v0
|
image: tea.shupogaki.org/yuruc3/pbsupper:v0.2.1
|
||||||
environment:
|
environment:
|
||||||
LOCAL_DATASTORE: somethingSomething
|
LOCAL_DATASTORE: somethingSomething
|
||||||
REMOTE_DATASTORE: somethingSomething
|
REMOTE_DATASTORE: somethingSomething
|
||||||
REMOTE_PBS: somethingSomething
|
REMOTE_PBS: somethingSomething
|
||||||
|
|
||||||
|
RUN_SCHEDULE: "45 10 * * SUN"
|
||||||
|
|
||||||
HOST: somethingSomething
|
HOST: somethingSomething
|
||||||
HOST_SSH_PORT: somethingSomething
|
HOST_SSH_PORT: somethingSomething
|
||||||
HOST_USR: somethingSomething
|
HOST_USR: somethingSomething
|
||||||
|
|||||||
4
main.py
4
main.py
@@ -32,7 +32,7 @@ AUTO_ADD_NAME: Final[str] = os.getenv("AUTO_ADD_NAME", "autoBackupScript_one-sho
|
|||||||
|
|
||||||
RUN_SCHEDULE: Final[str] = os.getenv("RUN_SCHEDULE", "45 17 * * 5")
|
RUN_SCHEDULE: Final[str] = os.getenv("RUN_SCHEDULE", "45 17 * * 5")
|
||||||
RUN_SCHEDULE_TZ: Final[str] = os.getenv("RUN_SCHEDULE_TZ", "Europe/Stockholm")
|
RUN_SCHEDULE_TZ: Final[str] = os.getenv("RUN_SCHEDULE_TZ", "Europe/Stockholm")
|
||||||
RUN_ONE_SHOT: Final[bool] = bool(os.getenv("RUN_ONE_SHOT", False))
|
RUN_ONE_SHOT: Final[bool] = (os.getenv("RUN_ONE_SHOT", "false").lower() == "true")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ def theCodeBasically():
|
|||||||
|
|
||||||
if time.monotonic() - SYNC_JOB_DATE >= (PBS_MAX_RUNTIME_MIN * 60):
|
if time.monotonic() - SYNC_JOB_DATE >= (PBS_MAX_RUNTIME_MIN * 60):
|
||||||
# print(SYNC_JOB_DATE - time.monotonic())
|
# print(SYNC_JOB_DATE - time.monotonic())
|
||||||
|
|
||||||
# Forcefully skip if these tasks are running. reader task is, I think, PVE backup
|
# Forcefully skip if these tasks are running. reader task is, I think, PVE backup
|
||||||
# Also otherjob is something else and it is better to wait if there is one otherjob
|
# Also otherjob is something else and it is better to wait if there is one otherjob
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ data:
|
|||||||
# Alternatively you can also use this option instead of PRIVATE_KEY: 123...
|
# Alternatively you can also use this option instead of PRIVATE_KEY: 123...
|
||||||
|
|
||||||
stringData:
|
stringData:
|
||||||
PRIVATE_KEY: |
|
HOST_USR_SSHKEY: |
|
||||||
-----BEGIN OPENSSH PRIVATE KEY-----
|
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||||
123...
|
123...
|
||||||
-----END OPENSSH PRIVATE KEY-----
|
-----END OPENSSH PRIVATE KEY-----
|
||||||
@@ -48,11 +48,13 @@ data:
|
|||||||
PBS_TASK_LIMIT: somethingSomething
|
PBS_TASK_LIMIT: somethingSomething
|
||||||
PBS_MAX_RUNTIME_MIN: somethingSomething
|
PBS_MAX_RUNTIME_MIN: somethingSomething
|
||||||
PBS_MAX_SHUT_MIN: somethingSomething
|
PBS_MAX_SHUT_MIN: somethingSomething
|
||||||
AUTO_ADD_NAME : somethingSomething
|
AUTO_ADD_NAME: somethingSomething
|
||||||
|
RUN_SCHEDULE: "45 10 * * SUN"
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: batch/v1
|
apiVersion: apps/v1
|
||||||
kind: CronJob
|
kind: Deployment
|
||||||
|
|
||||||
metadata:
|
metadata:
|
||||||
name: pbsupper
|
name: pbsupper
|
||||||
namespace: CHANGE_ME
|
namespace: CHANGE_ME
|
||||||
@@ -61,52 +63,52 @@ metadata:
|
|||||||
idrac: v7
|
idrac: v7
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
schedule: "*/15 * * * *"
|
replicas: 1
|
||||||
timeZone: "Europe/Stockholm"
|
|
||||||
concurrencyPolicy: Forbid
|
|
||||||
|
|
||||||
successfulJobsHistoryLimit: 3
|
selector:
|
||||||
failedJobsHistoryLimit: 3
|
matchLabels:
|
||||||
|
app: pbsupper
|
||||||
|
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: pbsupper
|
||||||
|
server: Server-1
|
||||||
|
idrac: v7
|
||||||
|
|
||||||
jobTemplate:
|
|
||||||
spec:
|
spec:
|
||||||
backoffLimit: 2
|
automountServiceAccountToken: false
|
||||||
|
|
||||||
template:
|
securityContext:
|
||||||
spec:
|
appArmorProfile:
|
||||||
restartPolicy: Never
|
type: RuntimeDefault
|
||||||
automountServiceAccountToken: false
|
|
||||||
|
containers:
|
||||||
|
- name: pbsupper
|
||||||
|
image: tea.shupogaki.org/yuruc3/pbsupper:v0.2.1
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: pbsupper-deployment-1-secretmap
|
||||||
|
- configMapRef:
|
||||||
|
name: pbsupper-deployment-1-configmap
|
||||||
|
|
||||||
securityContext:
|
securityContext:
|
||||||
appArmorProfile:
|
runAsUser: 1600
|
||||||
|
runAsGroup: 1600
|
||||||
|
runAsNonRoot: true
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
capabilities:
|
||||||
|
drop:
|
||||||
|
- ALL
|
||||||
|
seccompProfile:
|
||||||
type: RuntimeDefault
|
type: RuntimeDefault
|
||||||
|
|
||||||
containers:
|
resources:
|
||||||
- name: pbsupper
|
limits:
|
||||||
image: tea.shupogaki.org/yuruc3/pbsupper:v0
|
cpu: 200m
|
||||||
imagePullPolicy: IfNotPresent
|
memory: 128Mi
|
||||||
|
requests:
|
||||||
envFrom:
|
cpu: 100m
|
||||||
- secretRef:
|
memory: 64Mi
|
||||||
name: pbsupper-deployment-1-secretmap
|
|
||||||
- configMapRef:
|
|
||||||
name: pbsupper-deployment-1-configmap
|
|
||||||
|
|
||||||
securityContext:
|
|
||||||
runAsUser: 1600
|
|
||||||
runAsGroup: 1600
|
|
||||||
runAsNonRoot: true
|
|
||||||
allowPrivilegeEscalation: false
|
|
||||||
capabilities:
|
|
||||||
drop:
|
|
||||||
- ALL
|
|
||||||
seccompProfile:
|
|
||||||
type: RuntimeDefault
|
|
||||||
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpu: 200m
|
|
||||||
memory: 128Mi
|
|
||||||
requests:
|
|
||||||
cpu: 100m
|
|
||||||
memory: 64Mi
|
|
||||||
Reference in New Issue
Block a user