Shell Scripts

MySQL dumps from a cron task

Create a cron task that generates a dump file from a MySQL database.

Bash file

This bash function creates a dump file from a database with a timesamp.


create_dump () {
  TIME=$(date '+%Y-%m-%d_%H-%M-%S')
  /usr/bin/mysqldump --single-transaction -u $1 -p$2 -h localhost --all-databases > /dumps/$3-$TIME.sql

Call the function with the database user, database password and the output filename (without timestamp) on parameters.

create_dump db_user db_password file_name


Add a cron task that execute the script. This exemple will create a dump file every sunday at 19h.

0       0       19      *       0       /crons/ >> /logs/dumps.log 2>&1

Compress files with gzip

Compress the Javascript and CSS files on the server for optimize web speed. It will be compressed into new files with a .gz extension. [ read ]

List files with options

List files on the current path on vertical display with invislible files, file permisions, owner and size in human readable format. [ read ]