Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name dump files differently for each day #710

Open
sasharevzin opened this issue Jul 8, 2020 · 0 comments
Open

Name dump files differently for each day #710

sasharevzin opened this issue Jul 8, 2020 · 0 comments

Comments

@sasharevzin
Copy link
Collaborator

Here's an example of how you could do this in bash. The below code sorts a list of archive names that are older than a cutoff time, and creates a command to delete them. This could be changed to work with filenames.

Another option would be to use find to look for files created before a certain day. However, the create date could be misleading.

cutoff_date="backup-$(/bin/date -u --iso-8601=seconds -d '-3 months')"
archives="$(/usr/bin/tarsnap --list-archives | /usr/bin/sort)"
cutoff_archives=""
cutoff_command="/usr/bin/tarsnap --humanize-numbers -d"

while IFS=' ' read -r archive; do
    cutoff_archive=$(echo -e "${cutoff_date}\n${archive}" \
            | /usr/bin/sort \
            | /usr/bin/head -n 1 \
            | /bin/grep -v -F "$cutoff_date" || true)
    if [ -z "$cutoff_archive" ]; then
        continue
    fi
    if [ -z "$cutoff_archives" ]; then
        cutoff_archives="${cutoff_archive}"
    else
        cutoff_archives="${cutoff_archives}\n${cutoff_archive}"
    fi
    cutoff_command="${cutoff_command} -f ${cutoff_archive}"
done <<< "$archives"

Originally posted by @auspicacious in https://github.com/Safecast/safecastapi/pull/699/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant