Initial commit
This commit is contained in:
commit
4653935be7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
variables.conf
|
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Firefox Backup
|
||||||
|
|
||||||
|
This script performs a backup (archiving) of Firefox profile to a backup directory (ideally located on a different volume). As its purpose is to be run at computer shutdown (see service file), it also removes, if it exists, the 10-day old archive.
|
||||||
|
|
||||||
|
### Files
|
||||||
|
* `firefox-backup.sh` performs a save of you Firefox profile.
|
||||||
|
* `variables.conf.templates` contains examples variables definitions, and should be copied locally to `variables.conf`
|
||||||
|
(with any required modifications).
|
||||||
|
* `systemd-templates/` contains Systemd units templates for running the script unattended.
|
||||||
|
#### Installation
|
||||||
|
* `install.sh` copies Systemd templates to their destination, and enables backup for the user running the script.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
* If your backup directory is not on root volume, you may want to add a drop-in for the service unit, with
|
||||||
|
`Requires=<mount-point>.mount`
|
||||||
|
|
||||||
|
### TODO
|
19
firefox-backup.sh
Normal file
19
firefox-backup.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/variables.conf"
|
||||||
|
|
||||||
|
# Remove old archive
|
||||||
|
old="$backups_directory/profile-$(date -d "-10 days" +'%Y%m%d').tgz"
|
||||||
|
if [[ -f $old ]]; then
|
||||||
|
rm $old
|
||||||
|
echo "Removed $old"
|
||||||
|
else
|
||||||
|
echo "No old archive to remove."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Save profile
|
||||||
|
if [[ ! -f "$backups_directory/profile-$(date +'%Y%m%d').tgz" ]]; then
|
||||||
|
tar zcf "$backups_directory/profile-$(date +'%Y%m%d').tgz" $firefox_data_path/$profile_name
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
21
install.sh
Executable file
21
install.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
run_directory=$(dirname "$0")
|
||||||
|
user=$(whoami)
|
||||||
|
|
||||||
|
echo "Copying Systemd units to system directory..."
|
||||||
|
sudo cp $run_directory/systemd-templates/firefox-backup-.service /etc/systemd/system/firefox-backup-$user.service
|
||||||
|
sudo sed -i -e "s/PH_USER/$user/g" /etc/systemd/system/firefox-backup-$user.service
|
||||||
|
sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/firefox-backup-$user.service
|
||||||
|
|
||||||
|
echo "Reloading Systemd..."
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
echo "Enabling service (and starting it so a backup occurs at next shutdown)..."
|
||||||
|
sudo systemctl enable --now firefox-backup-$user.service
|
||||||
|
|
||||||
|
echo "------------------------------------------------------------------------"
|
||||||
|
echo "Make sure you set variables.conf!"
|
||||||
|
echo "If your backup directory is not on root volume, please add a drop-in with Requires=X.mount to /etc/systemd/system/firefox-backup-$user.service."
|
||||||
|
echo "------------------------------------------------------------------------"
|
||||||
|
echo "Finished install. Exiting..."
|
||||||
|
exit 0
|
15
systemd-templates/firefox-backup-.service
Normal file
15
systemd-templates/firefox-backup-.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Backup PH_USER's Firefox profile before shutdown
|
||||||
|
DefaultDependencies=no
|
||||||
|
Before=halt.target shutdown.target reboot.target poweroff.target
|
||||||
|
# A drop-in with Requires=X.mount may come handy if the target is not the root volume
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
User=PH_USER
|
||||||
|
ExecStart=/usr/bin/true
|
||||||
|
ExecStop=PH_DIRECTORY/firefox-backup.sh
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
7
variables.conf.template
Normal file
7
variables.conf.template
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copy this file as variables.conf, with the correct values
|
||||||
|
|
||||||
|
backups_directory="$HOME/firefox" # FIXME make sure you change this parameter
|
||||||
|
firefox_data_path="$HOME/.mozilla/firefox"
|
||||||
|
profile_name='profile'
|
Loading…
Reference in New Issue
Block a user