Are there any best practices for testing delete scripts on a production system to avoid data loss?

When testing delete scripts on a production system to avoid data loss, it is essential to first backup the data before running the script. Additionally, it is recommended to test the script on a staging environment or with a subset of data to ensure it functions as expected without unintended consequences.

// Example code for testing delete script with backup and on staging environment

// Backup the data before running the delete script
$backupFile = 'backup.sql';
exec("mysqldump -u username -ppassword dbname > $backupFile");

// Test the delete script on a staging environment or with a subset of data
// This can help identify any issues or unintended consequences before running it on the production system