Tuesday, October 21, 2014

How to use RSYNC to compare 2 directories / folders and then create a 3rd directory with only the files that are new / different?

It took me a long while to finally create an rsync command to do what I needed correctly. This can be used to manage server backup folders or just synchronizing folders.

In my case, I have 2 very similar folders. FolderA is my "live" real site. "FolderB" is my backup copy of FolderA.

In order to keep my FolderB backup copy synchronized with the real FolderA website, I need to use rsync, but only find files that are different in any way, new or modified. For example, if I updated a PHP file in real site, I want it copied to the backup site and if someone uploaded a picture on the real site - I want that new file copied to the backup folder as well.

Please note that command below uses "--dry-run" parameter, keep it - it means nothing will actually be done or changed / written until you delete the --dry-run parameter from the command. It just means its in "test mode" and won't destroy anything until removed.

Because I don't want the files automatically written into my backup folder, I am creating a 3rd folder called "difference" and that's where ALL updated files from FolderA (real site) will be created. This means that I need to copy the "difference" folder into my backup folderB (overwrite any existing files in folderB with the ones from difference folder).

Confused yet? I think I am. Summary is: compare real site folderA to backup folderB and create the updated files inside a brand new /difference/ folder.

The command: 

rsync -rv --checksum --exclude '.htaccess' --exclude 'wp-config.php' --progress --stats --dry-run --compare-dest=/var/www/html/folderB/ /var/www/html/folderA/ /var/www/html/difference

  • note that I am excluding 2 files from being synchronized, modify or delete the exclude parameters as you see fit for your needs
  • folderA = your real site / your source of all up to date changes
  • folderB = this is your backup folder
  • difference = this is the brand new folder where updated files from folderA will be written that do not exist or are not up-to-date in folderB
Don't forget to remove --dry-run parameter to actually write the files for real in the /difference/ directory! 

Monday, March 24, 2014

Converting old MySQL passwords to MySQL 5.6 (16 characters to 41 characters)

  • Remove or comment old_passwords = 1 in my.cnf
Restart MySQL. If you don’t, MySQL will keep using the old password format, which will mean that you cannot upgrade the passwords using the builtin PASSWORD() hashing function.
The old password hashes are 16 characters, the new ones are 41 characters.
  • Connect to the database, and run the following query:
    SELECT user, Length(Password) FROM mysql.user;
This will show you which passwords are in the old format, ex:
| user     | Length(`Password`) |
| root     |                 41 |
| root     |                 16 |
| user2    |                 16 |
| user2    |                 16 |
Notice here that each user can have multiple rows (one for each different host specification).
To update the password for each user, run the following:
UPDATE mysql.user SET Password = PASSWORD('password') WHERE user = 'username';
Finally, flush privileges:

Wednesday, March 19, 2014

How to upgrade Plesk MySQL to Percona MySQL 5.6 (latest)

Plesk admin panel usually ships with MySQL 5.1 and if you are looking to upgrade it to 5.6 the process (at least for me) was not quite clear, with lots of little issues along the way. I learned a couple of things that are not immediately obvious and hope to capture them along the way in this quick guide. Here is my version of the steps necessary to upgrade MySQL 5.1 to Percona MySQL Server (and client). (Big shout-out to this blogger as well for clearing things up very nicely: http://www.theshell.guru).

Quick Note on "Why upgrade to Percona MySQL 5.6"
  • In short, Percona MySQL server is a modified MySQL 5.6 distribution that is optimized for maximum performance and will improve the overall performance of your database services (in theory, in most cases).

Starting Configuration
  • CentOS 64 Bit
  • Plesk 11.5+ with standard default packages installed
  • MySQL 5.1