Created
September 4, 2018 10:08
-
-
Save lwolf/89402244b7f0d83f7405fad8c207118f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
start=$(date -ud 20170413 "+%s") # start time in epoch time (seconds since Jan. 1st, 1970) | |
end=$(date -ud 20180831 "+%s") # end time | |
period=$((86400 * 7)) # 86400 is 24 hours | |
for ((i=start; i <= end; i+=$period)); do | |
FROM="$(date -ud "@$i" +%Y-%m-%d)" | |
TILL="$(date -ud "@$(($i + $period))" +%Y-%m-%d)" | |
echo "dumping data for period from $FROM till $TILL" | |
psql -c "COPY (select * from <TABLE> where <datefield> >= '${FROM}' and <datefield> < '${TILL}' ORDER BY <datefield>) TO STDOUT CSV DELIMITER E'\t' HEADER QUOTE E'\b' NULL AS '';" | gzip > /tmp/dump_${FROM}_${TILL}.tsv.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment