Use ISO 8601 date format for backup filenames

With previous `%D` format preventable errors like

```
tar (child): /data/backups/backup-09/05/22-03-22-03.tar.gz: Cannot open: No such file or directory
```

will occur. Let's use a more sane[^1] date format where possible.

The -I flag to date(1) was added in roughly 1999[^2] and is portable across
GNU coreutils and BusyBox. Piping to tr(1) to remove colons in filenames
is largely a Windows-compatibility concern, as Win32 does not allow for
that character in filenames[^3], and it's possible that the backups target
directory could be a volume mount to a Windows host (for example on
Docker Desktop For Windows).

[^1]: https://xkcd.com/1179/
[^2]: https://unix.stackexchange.com/a/164834
[^3]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions

Co-Authored-By: Josh Klar <josh@zulip.com>
This commit is contained in:
AUX
2022-09-05 05:47:32 +02:00
committed by Alex Vandiver
parent 33edaf380b
commit 24678b6e5b

View File

@@ -478,7 +478,7 @@ appManagePy() {
appBackup() {
echo "Starting backup process ..."
local TIMESTAMP
TIMESTAMP=$(date "+%D-%H-%M-%S")
TIMESTAMP=$(date -u -Iseconds | tr ':' '_')
if [ -d "/tmp/backup-$TIMESTAMP" ]; then
echo "Temporary backup folder for \"$TIMESTAMP\" already exists. Aborting."
echo "Backup process failed. Exiting."