Feedback on BASH backup script

  • Run nightly with crontab:

    0 0 * * * /bin/bash /home/ubuntu/scripts/ >/dev/null 2>&1
    # Delete backups older than 3 days
    three_days=$(date +'%m-%d-%y' -d '3 days ago')
    if [ -e "/home/ubuntu/dump.$three_days.rdb" ]; then
        rm "/home/ubuntu/dump.$three_days.rdb"
        echo "No dump.rdb older than 3-days found!"
    if [ -e "/home/ubuntu/nodebb_assets_$three_days.tar.gz" ]; then
        rm "/home/ubuntu/nodebb_assets_$three_days.tar.gz"
        echo "Removing nodebb_assets older than 3-days!"
        echo "nodebb_assets.tar.gz older than 3-days not found!"
    # Backup NodeBB assets
    cd /home/ubuntu/Node/public || exit 1
    tar -czf /home/ubuntu/nodebb_assets_"$(date +'%m-%d-%y')".tar.gz ./uploads
    # Backup Redis DB
    cp /var/lib/redis/dump.rdb /home/ubuntu/dump."$(date +'%m-%d-%y')".rdb

  • Admin

    Thanks for the write-up @Guiri, always nice to read about other peoples' implementations.

    Has anyone investigated the use of logrotate for rotating backups?

Log in to reply


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.