New: bash history backup systemd.units

This commit is contained in:
Akemi Izuko 2023-12-23 20:14:10 -07:00
parent e64d367d18
commit b3e5eaf11d
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
3 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,9 @@
[Unit]
Description=Backing up bash history
Wants=bash_eternal_backup.timer
[Service]
User=root
Group=root
Type=oneshot
ExecStart=/usr/local/bin/bash_eternal_backup.sh

View file

@ -0,0 +1,11 @@
[Unit]
Description=Backing up bash history
Requires=bash_eternal_backup.service
[Timer]
Unit=bash_eternal_backup.service
OnCalendar=*-*-* *:00/3
RandomizedDelaySec=3min
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Backup the .bash_eternal_history file of select users. Files should all be
# named in the format
#
# ${hostname}_${user}_bash_hist
declare -r backup_p=/home/emiliko/safe/bash_eternal_backups
declare -r backup_user=emiliko
mkdir -p "$backup_p"
declare -ar backups=(\
/home/emiliko/.bash_eternal_history
"${backup_p}/mirrorside_emiliko_bash_hist"
/root/.bash_eternal_history
"${backup_p}/mirrorside_root_bash_hist"
)
for ((i = 0; i < ${#backups[@]}; i += 2)); do
declare from="${backups[i]}"
declare to="${backups[i+1]}"
rsync "$from" "$to"
chmod 400 "$to"
chown "$backup_user" "$to"
chgrp "$backup_user" "$to"
done