#!/bin/bash
# make a backup
pg_dump -Fc --no-owner --dbname=postgresql://user:pswd@host:port/db_name > /folder/with/backups/db_`date +\%Y-\%m-\%d_\%T`.dump;
# delete files with *.dump older than 30 days
find . -name "*.dump" -type f -mtime 30 -exec rm -f {} \;
This file contains 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 | |
# Author: Oleh Pshenychnyi | |
# Date: 13.02.2021 | |
# | |
# Kill all processes matching a provided pattern. | |
# | |
# Usage: | |
# | |
# >> bash killer.sh celery |
This file contains 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 | |
# First line of the script is the shebang which tells the system how to execute | |
# the script: http://en.wikipedia.org/wiki/Shebang_(Unix) | |
# As you already figured, comments start with #. Shebang is also a comment. | |
# Simple hello world example: | |
echo Hello world! # => Hello world! | |
# Each command starts on a new line, or after a semicolon: | |
echo 'This is the first line'; echo 'This is the second line' |
This file contains 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
kill -9 $(ps aux | grep "REGEX" | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1 |
This file contains 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
#!/bin/bash | |
SSH_ENV="$HOME/.ssh/environment" | |
function start_agent { | |
echo "Initialising new SSH agent..." | |
(umask 066; /usr/bin/ssh-agent > "${SSH_ENV}") | |
. "${SSH_ENV}" > /dev/null | |
/usr/bin/ssh-add; | |
} |
Link with tutorial which covers a lot https://www.postgresqltutorial.com/
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
This manual contains some basic things I do for Ubuntu 18.04 server setup.
In general, it's not a mature production-ready setup, but it might be if you know how to polish it.
I use it for my personal needs e.q. file sharing, cloud file storage, serving static pages, running python/node apps, etc.
This file contains 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
// equivalent of cascade delete in MongoDB | |
/** | |
* Let's assume you have 2 related collections with next data structure. | |
* | |
* - `archive` | |
* { | |
* "_id" : ObjectId("5ce5138efe985e8424a79304"), | |
* "type" : "text", | |
* "headline" : "Curabitur non nulla sit amet nisl tempus convallis quis ac lectus." |