A Shell Script for Automating Backups

You can automate the backup process by making a small shell script which will create a daily backup file. How do you get cron to back up your database without overwriting the older backup? You can use a tiny shell script to add the date to your backup file. An example of a shell script you could use is shown below.

#!/bin/sh
date=`date -I`
mysqldump –all-databases | gzip > /var/backup/backup-$date.sql.gz

Creating a Cron Job

Login to the Standard Cron Manager under CPanel, You can set a job to run at a specific interval or at a specific times. Creating a cron job requires only three simple steps

  1. Enter your email address where it says: Please enter an email address where the cron output will be sent. Cron will send you a message when the job is executed, so you’ll know if there are any errors.
  2. In the Command to run: field, enter the full path to your script (you may need to check with your host for this).If you want to run a php file, the command will begin with php. For example, if you want to run RSS Import to update your Pligg feeds, you’d enter php and the path to your import_feeds.php file.

    Your path would look something like this:

    php /home/[your username]/public_html/rss/import_feeds.php.

    If you want to run the automatic backup script, which backs up your MySQL database and emails a copy to you, you’d enter /bin/sh (since this is a shell script), and the path to your script.

    Your path would look something like this:

    /bin/sh /home/[your username]/etc/upstart_cron_backup.sh

  3. Now you need to set the schedule.
    • Set the Minute(s). You can set a short interval here, or minutes of the hour (you can select multiple items in this—and the other— boxes by using the Shift and Command keys). If you don’t care about minutes, leave this set to 0).If you want to test things, set this to run Every Five Minutes. This is a good interval for running the script, checking your email for errors, and changing settings before your inbox gets inundated with cron messages.
    • Set the Hour(s). If you’re creating a cron job to run RSS Import, you might want to set this to Every Hour. If you’re setting up a backup script, you might choose an hour in the middle of the night for nightly backups.
    • Set the Day(s). You’ll probably want to leave this set to Every Day, but you can also choose specific days of the month.
    • Set the Weekday(s).
    • Set the Month(s).

When you’ve set the schedule, your cron job is done. Click the Save Crontab button. If you set it to a short interval for testing, you should have an email with your output within a few minutes. If there’s an error (usually a problem with your path), check your settings.

VTiger Tricks

Posted by Ivan Guan under Web Application

If you have installed vtiger with demo data and want to delete all data you can use the following SQL.

update vtiger_crmentity set deleted = 1

This SQL will set deleted flag of all existing module records in vtiger. You can revert back any record by setting deleted = 0.

If you want to sync only certain contact with vtiger

- Create new folder (for example: vtiger) under Contacts module in Outlook.
In vtiger outlook toolbar you can see preferences.
- In vtiger Preference you can see (Choose Contact Folder for Synhronization),
update the default Folder as the new folder (Eg ; Personal Folders\Contacts\vtiger)
Synhronize contacts. Now contacts from vtiger will be added into Outlook under newly created(vtiger) Folder.

Using a free CRM (Customer Relationship Management) online system, or one that is free open source software, is an excellent way to manage your sales leads. Free CRM software systems allow you the most inexpensive way to automate your lead list, sales pipeline, after the sale follow up, and sometimes even your inventory.

There are many CRM (Customer Relationship Management) software systems to choose from but, if you are just starting out in Sales, or if you own a small business, then before you invest in CRM software, it is a great idea to first consider trying some of the free CRM online (or web based) solutions. Some are available as free open source software for you to download to your computer. Once you try one or two of them, you will then have a better idea and know first hand what you want or don’t want “feature-wise” should you decide to purchase a CRM system down the road. Here is a list of websites to visit that offer free CRM software.

List of Free CRM Online Services and Free Open Source Software

  • FreeCRM.com – This is a very popular free CRM system and will no doubt cover all of your needs for sales lead management. This system is an online or web-based service so you do not need to download any software. It also makes it easy to access from any computer when you are away from your office. It’s easy to use with a long list of features. Register for free.
  • SalesForce.com - Salesforce CRM is another free CRM online service; there is no need to download anything to your computer. The Personal Edition is free for a single user only. Register an account for free.
  • Zoho.com – Zoho offers a free online CRM solution for up to three users. This system also has features that can accommodate the small business owner with an ingetrated inventory management system. Register for free.
  • Vtiger.com - Vtiger is free open source software for CRM. It is available for both Windows and Linux systems. It offers many features that were developed mainly for the small to medium sized business. Free for anyone to download and use.
  • SassLight.com – SassLight is a free web based (or online) CRM solution. Very easy to use with video tutorials available on the website. Free to register and use for one person only.

// this function convert date from YYYY-MM-DD to DD-MM-YYYY in order to use in HTML table for example
function mysql2table($date) {

$new = explode(“-”,$date);
$a=array ($new[2], $new[1], $new[0]);

return $n_date=implode(“-”, $a);
}

// this function convert date from DD-MM-YYYY to YYYY-MM-DD in order to use in MySQL table in DATE format for example

function table2mysql($year,$month,$day) {

if ($day<=9) { $day=”0″.$day; }
if ($month<=9) { $month=”0″.$month; }
$a=array ($year, $month, $year);

return $n_date=implode(“-”, $a);
}

The Microsoft Access Order Entry form you created contains all the information that your customer reps need to take a phone order. But every now and then the customer rep needs to access another form that has information that isn’t on the order form.

Instead of adding a subform to the order form, you can add a command button that let’s your rep pop open the desired form when needed. For example, a customer may need to change their e-mail address, which may be kept on the Customer E-mail Address form.

To create a command button that, when clicked, will pop open the necessary form, follow these steps:

  1. Open the Order Entry form in design mode.
  2. Click the Command Button tool on the toolbox and click and drag it to insert the command button control on the Order Entry form.
  3. Right-click the command button and select Properties.
  4. Under the Format tab, change the caption to E-mail Address.
  5. Select the Event tab, click the On-Click Property’s drop-down menu, and then select Event Procedure.
  6. Click the On-Click Property’s Build button.
  7. Enter the following command at the prompt:
DoCmd.OpenForm "Customer E-mail Addresses"
  1. Press [Alt][Q].

Now when your reps’ customers need to update their e-mail addresses, the rep can click the command button to access the correct form and make the necessary changes.

Referential integrity is an important concept in database design. The term refers to a state when all the references in a database are valid and no invalid links exist between the various tables that make up the system. When referential integrity exists, any attempt to link to a record which does not already exist will fail; this helps prevent user errors, producing a more accurate (and useful) database.

Referential integrity is usually implemented through the use of foreign keys. For a long time, the popular open-source RDBMS MySQL did not support foreign keys, citing concerns that such support would erode RDBMS speed and performance. However, given the high volume of user interest in this feature, recent versions of MySQL have implemented support for foreign keys through the new InnoDB table engine. Consequently, maintaining referential integrity within the tables that make up a database has become significantly simpler.

In order to set up a foreign key relationship between two MySQL tables, three conditions must be met:

  1. Both tables must be of the InnoDB table type.
  2. The fields used in the foreign key relationship must be indexed.
  3. The fields used in the foreign key relationship must be similar in data type.

The best way to understand how this works is with an example. Begin by creating two tables (Listing A), one listing animal species and their corresponding codes (table name: species) and the other listing animals in a zoo (table name: zoo). The idea here is to link the two tables by the species code, so that only those entries in the zoo table which have a valid species code in the species table are accepted and saved to the database.

Listing A

mysql> CREATE TABLE species (id TINYINT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) ENGINE=INNODB;
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO species VALUES (1, ‘orangutan’), (2, ‘elephant’), (3, ‘hippopotamus’), (4, ‘yak’);
Query OK, 4 rows affected (0.06 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> CREATE TABLE zoo (id INT(4) NOT NULL, name VARCHAR(50) NOT NULL, FK_species TINYINT(4) NOT NULL, INDEX (FK_species), FOREIGN KEY (FK_species) REFERENCES species (id), PRIMARY KEY(id)) ENGINE=INNODB;

Important: For non-InnoDB tables, the FOREIGN KEY clause is ignored.

As the above illustrates, a foreign key relationship now exists between the fieldszoo.species and species.id. An entry in the zoo table will be permitted only if the corresponding zoo.species field matches a value in the species.idfield. This is clearly visible in the following output, which demonstrates what happens when you attempt to enter a record for Harry Hippopotamus with an invalid species code:

mysql> INSERT INTO zoo VALUES (1, ‘Harry’, 5);
ERROR 1216 (23000): Cannot add or update a child row: a foreign key constraint fails

Here, MySQL checks the speciestable to see if the species code exists and, finding that it does not, rejects the record. Contrast this with what happens when you enter the same record with a valid species code (one that already exists in the species table):

mysql> INSERT INTO zoo VALUES (1, ‘Harry’, 3);
Query OK, 1 row affected (0.06 sec)

Here, MySQL checks the species table to see if the species code exists and, finding that it does, permits the record to be saved to the zoo table.

To delete a foreign key relationship, first use the SHOW CREATE TABLE command to find out InnoDB’s internal label for the field (Listing B).

Listing B

+——-+—————————————————+
| Table | Create Table                                      |
+——-+—————————————————+
| zoo   | CREATE TABLE `zoo` (
  `id` int(4) NOT NULL default ’0′,
  `name` varchar(50) NOT NULL default ”,
  `FK_species` tinyint(4) NOT NULL default ’0′,
  KEY `FK_species` (`FK_species`),
  CONSTRAINT `zoo_ibfk_1` FOREIGN KEY (`FK_species`)
  REFERENCES `species` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+——-+—————————————————-+

And then use the ALTER TABLE command with the DROP FOREIGN KEY clause, as below:

mysql> ALTER TABLE zoo DROP FOREIGN KEY zoo_ibfk_1;
Query OK, 1 row affected (0.11 sec)
Records: 1  Duplicates: 0  Warnings: 0

To add a foreign key to an existing table, use the ALTER TABLE command with an ADD FOREIGN KEY clause to define the appropriate field as a foreign key:

mysql> ALTER TABLE zoo ADD FOREIGN KEY (FK_species) REFERENCES species (id);
Query OK, 1 rows affected (0.11 sec)
Records: 1  Duplicates: 0  Warnings: 0

As the examples above illustrate, foreign key relationships can play an important role in catching data entry errors, and implementing them usually results in a stronger, better-integrated database. On the other hand, it’s worthwhile noting that performing foreign key checks is a resource-intensive process and defining complicated inter-relationships between tables can result in a significant performance drop. Therefore, it’s important to always balance referential integrity considerations with performance considerations, and use foreign keys judiciously to ensure an optimal mix of speed and strength.

Removing Malicious Virus MS32DLL

Posted by Ivan Guan under Windows

About the virus

This virus is somewhat marked as a Trojan virus, well, a lot of users doesn’t know it’s origin but it does take it some pretty nasty habits with it. It comes with the harmless look of MS32DLL.dll, but it comes with a very odd extention, “.vbs” (Visual Basic Script file). This sort of files can be run automatically if it is executed from the Auto run.When this virus effects one computer, it will automatically clones itself and transfer to any external drive, let it be a thumb drive, an external hardisk, or even a flash card (like SD Card, MMC or Compact Flash). I read a forum stated that some of the other virus that carries the same virus filename also put a text “Hacked by Godzilla” Title bar on Internet Explorer. And it will continue to infect any computer that connects to it.

So far I am not sure whether it is infecting throughout the private network, but I will update if it does.

How Do I Remove It?

There are quite a few steps to remove this Trojan but if your antivirus detects it earlier and erased it you are one step less to complete this detail task:1. Finding potential processes running- Press CTRL, ALT and DELETE key together. You will open the Windows Task Manager.
- Click the Processes tab, and comb through the list and see whether there is a program called wscript.exe is running. If you find it, click on it and click End Process.
- After that you can close the Task Manager window.

2. Finding the virus (for those who were not detected by the antivirus – for Microsoft Windows)

- Go to My Computer
- Click Tools at the top bar –> Folder Options
- When you come to the Folder Options window, click on the View tab
- Look for Hidden files and folders
- Click on Show hidden files and folders
- Press OK
- Once the window is closed, click on your C drive once.
- Right click and select Open from the menu bar
- Once you are in there, look for whether there is a filename called MS32DLL.dll.vbs
- If you can’t find it in C (like I did), look in C:\Windows
- If you still can’t find it, don’t worry, press F3 at the top row of your keyboard (in case you don’t know) and the search bar will be on your left. Click on All files and folders, and type in the file name MS32DLL.dll.vbs

If you don’t find any file in there, congratulations, you are one step out of it.
You can jump to step (4)

3. You found the virus

- Click on the file you found and press SHIFT key and DELETE key
- It will ask you “Are you sure you want to delete (the file name)”. Click Yes
- If you find more than one location that has MS32DLL.dll.vbs, then you need to repeat the steps in (3)

4. Editing the Windows Register (do it with full of caution!)

- Click Start –> Run
- Type regedit and press ENTER
- You will come to the Registry Editor window
- On your left there will be the registry directories. Look for:
HKEY_LOCAL_MACHINE –> Software –> Microsoft –> Windows –> Current Version –> Run
- If there is a MS32DLL in there, delete the entry.
- Then you need to look for:
HKEY_CURRENT_USER –> Software –> Microsoft –> Internet Explorer –> Main
- If you see the Window Title has “Hacked by Godzilla” you should delete that entry.
- You can now close the Registry Editor window

5. Stop all auto runs in future (recommended move)

- Click on Start –> Run
- Type gpedit.msc and press ENTER
- You will come to the Group Policy window
- Go to User Configuration –> Administrative Templates –> System
- Look for Turn off Autoplay and double click it. You will come to Turn Off Autoplay Properties window.
- Click Enable and select All drives from the drop-down combo box.
(It is suggested to turn it off to avoid further potential virus infections in future)
- You can now close the Group Policy window

6. Stopping auto run virus programs (if have)

- Click on Start –> Run – Type msconfig and press ENTER. You will come to the System Configuration Utility window
- Click on the Startup tab, and look for any programs that runs under MS32DLL.dll.vbs
- If you find then, uncheck the checkbox on the left of the file
- Click Apply
- Click Close
- When you close the window it will ask you whether to restart or not. Click on Exit without Restart.

7. Hide your system files

- Go to My Computer
- Click Tools at the top bar –> Folder Options
- When you come to the Folder Options window, click on the View tab
- Look for Hide protected operating system file
- Click on Don’t show hidden files and folders
- Press OK

8. Restarting your PC

- Before restart, make sure that you empty your recycle bin
- Restart your PC
- You will see a windows prompt that you have changed your system configurations. Check on the checkbox not to remind you anymore and press ok.

Source: http://www.interstraits.biz

p.s looks like Malwarebytes’ Anti-Malware can detect and solve the problem.

Reduce number of files in Gallery

Posted by Ivan Guan under Webmaster

Gallery is a fantastic program to organise your photos. However, it generates a large number of files. This application alone is using 16,102 inodes in my server. As most server limits the number of inodes to be 50,000. Some of the tips to reduce the number of files would be handy.

Be sure to back up first.

  1. Removing the modules/*/locale/* and themes/*/locale/*/ folders is fine. you’ll still see g2′s American English default output.
  2. You can delete the g2data/cache (or just the g2data/cache/derivative) directory periodically (yours may be under a different path) at the expense of performance, as each page visit will have to rebuild those cached files from the original.
  3. Delete any modules in ./gallery2/modules that you don’t use, make sure they are deactivated / uninstalled first. You can also ”delete” from site admin, plugins
  4. Delete any themes you don’t use in ./gallery2/themes, of course making sure they aren’t activated (uninstall them!). Might be able to delete from the same place as above
  5. In each module, there are lots of .po and .mo files in each module/po directory (ie: ./gallery2/modules/uploadapplet/po). You should be safe to delete any languages you *don’t* use, but you can see this could quickly be time consuming. If you have shell access, you could do something like `find . -name ‘es.*’` to see all the “es” language files (is that spanish?). You could expand the find request until you are happy with the results (say, using regex) then add a “-delete” or “-exec rm ‘{}’ ‘;’” (depending on which it supports) to nuke all those language files. You might have to repeat it a few times with different file names specified so you can get them all w/o removing the languages you want to keep. This should save a lot of files too.
  6. You might consider de-activating all your modules, downloading the latest “minimal” release and blowing away your ./gallery2/ dir (after making a backup of course), copying the “config.php” from your backup and then making sure everything is going. Now, using the downloadable plugins, you can get modules with *only* the languages you want.

Improve Joomla’s search result

Posted by Ivan Guan under Joomla

Currently if you search a Joomla site using default search module and component, “Food Hamburgers” will return all pages with either “Food” or “Hamburgers”.

search-all-words.png

This isn’t particularly useful because people would prefer to see pages with both. Zorro, a regular and wise commenter on this blog has come up with a neat little hack available here at www.nitsche.org. Download it, save it as mod_search.php, backup your existing mod_search.php and upload this instead. Now, when people search your site, Joomla will use the “all words” search by default.

How to count files in Linux

Posted by Ivan Guan under Linux

To determine how many files there are in the current directory, put in

ls -1 | wc -l.

This uses wc to do a count of the number of lines (-l) in the output of ls -1. It doesn’t count dotfiles, but seems it will count the directory ./

To include subdirectory files, you can use ls -R | wc -l

To ignore directory ./ you can use find . -type f | wc -l

If you want to count only files and NOT include symbolic links (just an example of what else you could do), you could use ls -l | grep -v ^l | wc -l (that’s an “L” not a “1″ this time, we want a “long” listing here). grep checks for any line beginning with “l” (indicating a link), and discards that line (-v).