Skip to content

Instantly share code, notes, and snippets.

View saeedahadian's full-sized avatar
🎯
Focusing

Saeed Ahadian saeedahadian

🎯
Focusing
View GitHub Profile
@saeedahadian
saeedahadian / dcsl.sh
Created January 4, 2022 14:36
`docker-compose logs` command shows logs in the order that it receives them which is often not the chronological order. By using this script you can see logs of `docker-compose` sorted by timestamp.
#!/bin/bash
usage="Input piped docker-compose logs -t, or a file created from this command, to show logs lines sorted by time.\n\n Usage:\n\n $(basename "$0") [-h|--help] - this message\n $(basename "$0") - runs default docker-compose logs -t and sorts'em\n docker-compose logs -t|$(basename "$0") - pipe logs to this command\n $(basename "$0") my-compose.log - or choose file with logs to display\n\n"
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
case "$1" in
-h|--help) printf "$usage"
exit
;;
esac
if [ -t 0 ]; then
@saeedahadian
saeedahadian / use-docker-volume.sh
Created January 4, 2022 14:34
A simple bash script to backup or restore a docker volume on the server.
#!/bin/bash
case $1 in
backup)
docker run --rm -v $2:/volume -v $(pwd):/backup ubuntu tar cvf /backup/$2.tar /volume
;;
restore)
docker run --rm -v $(pwd):/backup -v $2:/volume ubuntu bash -c "cd /volume && tar xvf /backup/$2.tar --strip 1"