Feedback on BASH backup script



  • Run nightly with crontab:

    0 0 * * * /bin/bash /home/ubuntu/scripts/node_backup.sh >/dev/null 2>&1
    
    #!/bin/bash
    
    # 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"
    else
        echo "No dump.rdb older than 3-days found!"
    fi
    
    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!"
    else
        echo "nodebb_assets.tar.gz older than 3-days not found!"
    fi
    
    # 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?


 

| |