• How to use a Windows .bat file to delete files on a schedule

    This is how you delete files of a certain age using a scheduled task to execute a .bat file. These instructions mainly apply to Windows Server 2012 R2, but they are applicable to most newer (and older) versions of Windows. This is similar to the post I made many years ago but with some additions mainly around the commands you need to find files that are older than a certain date and then deleting them. It also focuses on Server 2012 R2 versus the older 2008.

    The first thing we want to do is create the batch file that we will use to delete the files older than X days. To do this we will need to use the forfiles command in Windows. This is a very handy command for batch files IMO. Here is a run down of the forfiles command and how to use it:
    Read the rest of this entry »

    Share
  • Shell script to get all WordPress databases and URL’s

    Below you will find a simple script that you can use to find all the databases and URL’s associated to wordpress sites in a shared database. This script requires a SQL user with the ability to ‘show databases’ and access to the DB’s you want to query.

    The script grabs a list of all the databases on the server then loops through them all retrieving the URL from the wp_options table. The script also takes into consideration the fact the the table might not actually be wp_options (could contain some random characters) so we use a wildcard there.





    Read the rest of this entry »

    Share
  • Simple Bash Automation for EC2 Instance Backups using Cron on a Mac Mini

    The problem that needed to be solved was to have a simple backup system that could be used to maintain a bunch of EBS backed Windows instances on AWS. We wanted to keep a weeks worth of backups, always discarding the older AMI’s. A local mac mini was used to run the necessary scripts and cron. We didn’t want just EBS snapshots, we wanted a full AMI everyday. There are other solutions if you just want to backup an EBS drive on a schedule, and even for this but this one suits our needs.

    Read the rest of this entry »

    Share
  • FTP script to automate file transfers to remote server

    Below you will find a FTP script that will allow you to automate your files transfers without requiring any user input. The only problem with this method is you will be putting a username and password into the script file, but having a simple automated FTP file upload or FTP file download probably outweighs the drawback.

    So to describe what this script does:
    First the script will tar and zip all files and folders in the /var/log/ folder to the home directory of the user who runs the script. This will create a dated zip file in the user’s home folder who ran the script. Then it will FTP the files to the remote host. You can then add the script to a cron job to execute it everyday, week, hour, etc.
    Read the rest of this entry »

    Share
  • Simple Postgresql Cron Backup

    Here is a very simple method to backup your postgresql DB using a cron job and the pg_dump command. The main problem people encounter when trying to automate the pg_dump command is the password input. Now you could easily create a local user with no password, but why would you want to do that.




    Read the rest of this entry »

    Share