Server backup
12 jan. 2014Backup and transfer for files between online of offline environments of this django installation consists of the following steps:
mysqldump -u username -ppassword > ~/backup/dbs/mysql_`date +%F_%H:%M:%S`.sql
Restore data to mysql database:
mysql -u username -ppassword database < restore.sql
Remove all rows of a table:
TRUNCATE TABLE table_name;
Update content in database: (via SQL terminal)
update table set field = replace(field, 'old', 'new');
Backup of files:
tar -zcvf ~/backup/site/django_`date +%F_%H:%M:%S`.tar.gz ~/webapps/django/myproject/
tar -zcvf ~/backup/site/images_`date +%F_%H:%M:%S`.tar.gz ~/webapps/static_media/
tar -zcvf ~/backup/site/files_`date +%F_%H:%M:%S`.tar.gz ~/webapps/static/fileupload/
Collect static
python2.7 ~/webapps/django/myproject/manage.py collectstatic
Restart apache
~/webapps/django/apache2/bin/restart
Secure copy
scp -P port -r target_path username@server:destination_path