Archive for the ‘Shell Scripts’ Category

Database Backup Script

Scenario: Create a backup script to take Backup of mysql databases on remote server to your local backup server and remove existing backups older than 7 days. Solution: #!/bin/bash DB_BACKUP=”/Databases/`date +%A`” DB_USER=”root” DB_PASSWD=”Pass@7rt5_890#” DB_HOST=’172.24.25.154′ # Remove backups older than 7 days find /Databases -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \; # […]

Download file from remote ftp

Scenario: Create a script to download the zipped database files from remote ftp server and import those database files to remote database server. Also do not forget to inflate the zipped files and remove them after import. Solution: ############ Download the zipped database files ############### /usr/bin/ncftpget -R -v -u “ftpuser” -p “password” ftp.someserver.com /home/localuser /home/ftpuser/database.sql.zip […]

Local Backup Script

Scenario: Create a Script to take backup of user Alex’s home directory to local systems /Backup directory. echo “*** Backup Script ***” echo echo “*** Script started at: $(date) on $(hostname)” # Define variables BACKUP_src=”/home/alex” BACKUP_dst=”/Backup” NOW=$(date +”%d-%m-%Y”) # echo “*** Backing up Alex home directory to $BACKUP_dst/$NOW…” /bin/cp -var $BACKUP_src $BACKUP_dst/$NOW # Backup confirmation […]