0x01#
Files, images, and audio/video generated in WeChat chat history are cached on the local disk. If not cleaned for a long time, they will occupy a large amount of storage space.
Although the WeChat Mac version has a space cleanup feature that allows you to directly delete all chat files with a specific person or group, it is a direct deletion without any options for selection or backup.
This situation is quite awkward. I searched online but couldn't find a good cleanup and archiving solution. Most of the information teaches you how to clean up and free up space, which is not very meaningful.
0x02#
Cleanup is relatively simple, but what I really want is to be able to archive and back up, because some chat files may be important or may be needed later. The text in chats does not occupy much space; the main issue is the various cached files.
If you simply sync the local WeChat cache directory directly to a sync disk or NAS, it cannot be well archived and managed.
Here’s a simple solution.
Write a simple shell script to filter out older files that need to be archived based on file time.
The Mac WeChat chat file directory is: ~/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\ Support/com.tencent.xinWeChat/2.0b4.0.9
Then, below, each WeChat account logged into the computer will generate an ID directory, for example:
fc4cea7edb2dde38c6ba91c9f1a5f288
.
The chat files generated by various chat units are located in Message/MessageTemp
within this directory.
Search and filter in this directory:
find ./ -mtime "+$clean_days"
This command can filter out files older than clean_days
days, and these files can be archived to NAS or other storage disks.
find ./ -mtime "+$clean_days" -exec sh -c '
mkdir -p "$0/${1%/*}"
mv -v "$1" "$0/$1"
' "$backupDir" {} \;
Here, the filtered files are synced to the backup disk, and the hierarchical directory structure of the files will also be created. The creation of this hierarchical directory is crucial for later recovery and querying of these files.
backupDir
is the backup directory; I simply used AFP to mount a shared folder on the NAS.
For related knowledge, check out https://support.apple.com/zh-cn/HT202181.
Here’s a mount command for reference:
mount_afp afp://username:password@host:port/volume backupDir
This way, you can achieve clear filtering, archiving, and backup recovery.
Check the results:
You can archive based on your required time period or other filtering criteria.
0x03#
Using remote sync tools like rsync is also possible, but it may not be very flexible. However, further research and improvement can be done later.
0x04#
If anyone needs the complete solution script code or the complete program, you can follow the abitmean public account and leave a message to request it. 😝