Although most people refer to computers when talking about a virus, the PlayStation 3 isn't immune from such malware; no such cases have been reported, but malware evolves regularly. If you suspect an infection on your console, Sony recommends using the PS3's System Restore to reformat the device and remove anything saved on the hard drive.
Insert an external drive into a free USB port on your PlayStation 3 console. The second player controller port is a good option since this process doesn't require two people.
Navigate to any data you wish to transfer. For example, you can transfer any of the items under Photos and Music, and you can find save game files in the folder "Saved Data Utility" under Games.
Press the "Triangle" button to open a submenu. Highlight "Move" and select your external drive to move the selected file. You'll need to do this for each individual file you want saved.
Return to the dashboard and navigate to the Settings category. Within this menu, select "Restore PS3 System" using the "X" button.
Press "X" to move through each screen. The console will ask if you can see the screen and announce its intent to fix the corrupted system. Wait for the bar to complete; the console will reboot and return to the main dashboard, functioning like brand new.
After reformatting the console, logging in to your PlayStation Network profile will let you download any purchases to the device again.
This doesn't guarantee you'll wipe a virus; if your console still experiences erratic behavior, you'll need to contact Sony.