Absolute Paths, Absolute Madness

Don't forget about them


So. our story begins last month when i moved servers.
i didn't set up a backup script because i felt that it was unnecessary as i had server backups enabled. Easy!

Until last week that is, when during a change to how i store what date a post was created on, i accidentally made everything on the same day.
why does sed change the creation date metadata anyway‽‽

I quickly found out that server backups are just images, snapshots, of the server, meaning I'd have to loose the last 24 hours of data from stuff like myfriendsare.gay which was a no go for me.

So. that absolutely sucked, luckily i had a partial backup in the form of the original images for my art. so i managed to automate the restoral of that for the most part, excluding about the previous two weeks.

After that, i decided to set up the amazing Backup Script!

I think it was a clever script;

#! /bin/bash

# Make Backups
tar -cvzf "./beefox.xyz/beefox-xyz-$(date +"%Y-%m-%dT%H:%M:%S").tar.gz" -C /root/beefox.xyz/ ./static/files/ ./SitePosts/ ./webMentio
ns && echo -e "\e[1m\e[38;2;238;170;102mFinished Site Backup\e[0m" &
T1=${!}
sudo -u postgres pg_dumpall -v | gzip -9 > "./postgres/postgres-$(date +"%Y-%m-%dT%H:%M:%S").gz" && echo -e "\e[1m\e[38;2;238;170;102
mFinished Postgres Backup\e[0m" &
T2=${!}
mongodump --gzip --archive="./mongodb/mongo-$(date +"%Y-%m-%dT%H:%M:%S").gz" && echo -e "\e[1m\e[38;2;238;170;102mFinished Mongo Back
up\e[0m" &
T3=${!}

wait ${T1}
wait ${T2}
wait ${T3}
echo -e "\e[1m\e[38;2;238;170;102mFinished All Backups\e[0m"

# Rsync
rsync --progress -e 'ssh -p23' --recursive . uXXXXXX@uXXXXXX.your-storagebox.de:buddyBackups/
echo -e "\e[1m\e[38;2;238;170;102mFinished Syncing\e[0m"
# Del Older then week
find * -mtime +7 -not -type d -not -name *.sh -exec rm {} \;
echo -e "\e[1m\e[38;2;238;170;102mRemoved Local Backups Older Then One Week\e[0m"

i set this to run at 4am my time every day, using chron.

The keen eyed among you have probably already spotted the problem.

At 4am 5 things happened.

  1. This site was backed up

  2. My postgres database was backed up

  3. My mongo database was backed up

All going perfectly! but then

  1. All Files In My Home Directory Were Uploaded

That's ok, just a bit of clean up, no worries.

  1. All Files, Older Then A Week, In My Home Directory Were Deleted.

Yeah. That happened.

Due to the fact that i had used relative paths in a lot of places, not only where files all over the place, but when it deleted the old backups, it deleted all files because * ran in home (~), instead of in ~/backups.

Luckily, as you can see in the order of events, i did have backups to restore everything.
Well, almost everything, i did have to rewrite my .env files. But that was ok.

I updated the script to use absolute paths. Let my story of my fall be your warning when you are doing something like this yourself.

Be Warned.