MySQL dump examples

Dump database to file with date in name:

mysqldump -u USERNAME -pSECRETPASSWORD --single-transaction --quick --lock-tables=false DBNAME_HERE > /home/backup/mysql/DBNAME_HERE_`date "+%Y-%m-%d-%H-%M"`.sql

Crontab version: dump every hour at minute 5

5 * * * * mysqldump -u USERNAME -pSECRETPASSWORD --single-transaction --quick --lock-tables=false DBNAME_HERE > /home/backup/mysql/DBNAME_HERE_`date "+\%Y-\%m-\%d-\%H-\%M"`.sql

Keep 2 folders synchronized

Code to copy all changes from one folder to another. I use it to copy changes from my local folder to development server mounted by SSHFS.

In example files are filtered. Only *.cpp and *.h files are copied.

while inotifywait -e modify,create,delete "/home/jskalski/p/prv/otserv/"; do
    rsync -zvur --include="*.cpp" --include="*.h" --exclude="*" "/home/jskalski/p/prv/otserv/" "/mnt/devserver/home/js/otserv/"
done

Find newest files in directory (recursively)

List files from oldest to newest, recursively.

find . -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -n |  awk '{print strftime("%Y-%m-%d %H:%M:%S", $1), $5}' | tail --lines=50

Result:

(...)
2019-04-19 12:21:31 ./klientotc/modules/gamelib/ui/uiminimap.lua
2019-04-19 15:04:22 ./klientotc/modules/game_hotkeys/hotkeys_manager.otui
2019-04-19 15:11:36 ./klientotc/modules/game_hotkeys/hotkeys_manager.lua
2019-04-19 16:18:34 ./klientotc/.git/index
2019-04-19 16:18:34 ./klientotc/modules/corelib/ui/uiminiwindowcontainer.lua
2019-04-19 16:33:01 ./klientotc/modules/corelib/ui/uiminiwindow.lua
2019-04-19 17:15:50 ./klientotc.zip
2019-04-23 07:35:34 ./klientotc/Kasteria.log
2019-04-25 07:25:25 ./klientotc/.idea/workspace.xml
2019-04-26 10:26:27 ./source/.idea/workspace.xml