if [ "-$1" = "-" ]; then
DAYSTR=$(date "+%Y-%m-%d" -d '-1 day')
else
DAYSTR=$1
fi
/usr/bin/mysqldump db torrent_file_info --default-character-set=utf8 -n -t --compact --extended-insert=FALSE --where="save_time like '${DAYSTR}%'" >file_info.sql
/usr/bin/mysqldump db torrent_download_url --default-character-set=utf8 -n -t --compact --extended-insert=FALSE --where="last_datetime like '${DAYSTR}%'" >download_url.sql
/usr/bin/mysql db --skip-column-names -e "select fl.infohash , SUBSTRING_INDEX(file_name, '.', -1) from torrent_file_list fl, torrent_file_info fi, (select infohash,max(file_length) as file_length from torrent_file_list group by infohash) t where fl.infohash = fi.infohash and fl.infohash = t.infohash and fl.file_length = t.file_length and fi.save_time like '${DAYSTR}%' ;">file.txt
tar -czvf ${DAYSTR}.tar.gz file_info.sql download_url.sql file.txt
if [ "-$1" = "-" ]; then
DAYSTR=$(date "+%Y-%m-%d" -d '-1 day')
else
DAYSTR=$1
fi
tar -xzvf $DAYSTR.tar.gz
mysql test -e 'truncate torrent_download_url;truncate torrent_file_info;'
mysql --default-character-set=utf8 test<download_url.sql
mysql --default-character-set=utf8 test<file_info.sql
mv file.txt /tmp/file.txt
mysqlimport -i test /tmp/file.txt