New: bash history backup systemd.units
This commit is contained in:
parent
e64d367d18
commit
b3e5eaf11d
9
systemd/system/bash_eternal_backup.service
Normal file
9
systemd/system/bash_eternal_backup.service
Normal 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
|
11
systemd/system/bash_eternal_backup.timer
Normal file
11
systemd/system/bash_eternal_backup.timer
Normal 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
|
27
systemd/system/timer-scripts/template.bash_eternal_backup.sh
Executable file
27
systemd/system/timer-scripts/template.bash_eternal_backup.sh
Executable 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
|
Loading…
Reference in a new issue